Here you can find the source of read(String fileName)
Parameter | Description |
---|---|
fileName | file's name |
public static byte[] read(String fileName)
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{ /**/* w w w . j a va2 s . co m*/ * 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; } }