Here you can find the source of read(File file)
Parameter | Description |
---|---|
file | file to be read |
public static byte[] read(File file)
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main{ /**//from ww w. j a v a 2s .c om * Read data from file * @param fileName file's name * @return file's data */ public static byte[] read(String fileName) { byte[] bytes = null; try { if (StringUtil.isEmpty(fileName)) { return null; } InputStream in = new BufferedInputStream(new FileInputStream( fileName)); bytes = new byte[in.available()]; in.read(bytes); in.close(); } catch (Exception ex) { throw new RuntimeException(ex); } return bytes; } /** * Read data from file * @param file file to be read * @return file's data */ public static byte[] read(File file) { byte[] bytes = null; try { InputStream ins = new BufferedInputStream(new FileInputStream( file)); bytes = new byte[ins.available()]; ins.read(bytes); ins.close(); } catch (Exception ex) { throw new RuntimeException(ex); } return bytes; } }