public static byte[] readFile(String filePath) { byte[] contents; Java.IO.File file = new Java.IO.File(filePath); int size = (int)file.Length(); contents = new byte[size]; try { FileStream inputStream = new FileStream(filePath, FileMode.OpenOrCreate); Java.IO.BufferedOutputStream bos = new Java.IO.BufferedOutputStream(inputStream); BufferedInputStream buf = new BufferedInputStream(inputStream); try { buf.Read(contents); buf.Close(); } catch (Java.IO.IOException e) { e.PrintStackTrace(); } } catch (Java.IO.FileNotFoundException e) { e.PrintStackTrace(); } return(contents); }
public static void saveFile(byte[] encodedBytes, String path) { try { Java.IO.File file = new Java.IO.File(path); FileStream inputStream = new FileStream(path, FileMode.OpenOrCreate); Java.IO.BufferedOutputStream bos = new Java.IO.BufferedOutputStream(inputStream); bos.Write(encodedBytes); bos.Flush(); bos.Close(); } catch (Java.IO.FileNotFoundException e) { e.PrintStackTrace(); } catch (Java.IO.IOException e) { e.PrintStackTrace(); } catch (Exception e) { } }