Conversion between java files and byte, and byte for java files
/*** Get the byte array of the specified File */private byte [] getBytes (String filePath) {byte [] buffer = null; try {file File = new File (filePath ); fileInputStream FCM = new FileInputStream (file); ByteArrayOutputStream bos = new ByteArrayOutputStream (1000); byte [] B = new byte [1000]; int n; while (n = FS. read (B ))! =-1) {bos. write (B, 0, n);} fiis. close (); bos. close (); buffer = bos. toByteArray ();} catch (FileNotFoundException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} return buffer;}/*** generate the file */public static void getFile (byte [] bfile, String filePath, String fileName) based on the byte array) {BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try {File dir = New File (filePath); if (! Dir. exists () & dir. isDirectory () {// determine whether the file directory exists dir. mkdirs ();} file = new File (filePath + "\" + fileName); fos = new FileOutputStream (file); bos = new BufferedOutputStream (fos); bos. write (bfile);} catch (Exception e) {e. printStackTrace ();} finally {if (bos! = Null) {try {bos. close () ;}catch (IOException e1) {e1.printStackTrace () ;}} if (fos! = Null) {try {fos. close ();} catch (IOException e1) {e1.printStackTrace ();}}}}