Java File read to byte array via BufferedInputStream

Description

Java File read to byte array via BufferedInputStream

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Main{
    public static byte[] readFile(String filename) throws IOException {
        File file = new File(filename);
        return readFile(file);
    }/*from  w  ww  .  j  a  v a2 s .co  m*/

    public static byte[] readFile(File file) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new
            FileInputStream(file));
        int bytes = (int) file.length();
        byte[] buffer = new byte[bytes];

        int readBytes = bis.read(buffer);
        bis.close();
        return buffer;
    }

}



PreviousNext

Related