Java File to Byte Array getBytes(File file)

Here you can find the source of getBytes(File file)

Description

get Bytes

License

Open Source License

Declaration

public static byte[] getBytes(File file) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static byte[] getBytes(File file) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(file);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bytes = new byte[1024];
        int n = 0;
        while ((n = fileInputStream.read(bytes)) != -1) {
            byteArrayOutputStream.write(bytes, 0, n);
        }/*from   w ww.j av  a2 s.  c o m*/
        byteArrayOutputStream.close();
        fileInputStream.close();

        return byteArrayOutputStream.toByteArray();
    }
}

Related

  1. getBytes(File file)
  2. getBytes(File file)
  3. getBytes(File file)
  4. getBytes(File file)
  5. getBytes(File file)
  6. getBytes(File file)
  7. getBytes(File file)
  8. getBytes(File file)
  9. getBytesFromFile(File f)