Posted By

alejandrosuch on 04/09/10


Tagged

file java array byte


Versions (?)

File to byte array


 / Published in: Java
 

  1. private static byte[] fileToByteArray(String fileName) throws Exception {
  2. FileInputStream fis = new FileInputStream(fileName);
  3.  
  4. byte buffer[] = new byte[4096];
  5. int length = -1;
  6.  
  7. while (true) {
  8. length = fis.read(buffer);
  9. if (length == -1){
  10. break;
  11. }
  12. baos.write(buffer, 0, length);
  13. }
  14.  
  15. fis.close();
  16.  
  17. return baos.toByteArray();
  18. }

Report this snippet  

You need to login to post a comment.