Here you can find the source of readAllFromFile(String file)
public static byte[] readAllFromFile(String file)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static final String ENCODING = "UTF-8"; public static byte[] readAllFromFile(String file) { FileInputStream fis = null; try {// w w w .j av a 2 s . co m fis = new FileInputStream(file); return readAllFrom(fis, false); } catch (Exception e) { throw new RuntimeException("Unable to read file:" + file, e); } finally { if (fis != null) { try { fis.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static byte[] readAllFrom(InputStream in, boolean chunked) { if (in == null) throw new RuntimeException("Stream can't be null"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { byte[] buf = new byte[1024]; int len; len = in.read(buf); //System.out.println("READ: " + len + "bytes for the first time"); while (len > 0) { bos.write(buf, 0, len); if (chunked) { byte[] check = new String(bos.toByteArray(), ENCODING) .trim().getBytes(ENCODING); if (check.length >= 1) { if (check[check.length - 1] == '0') { if (check.length == 1) break; if ((check[check.length - 2]) == '\n') { break; } } } } len = in.read(buf); } } catch (Exception e) { throw new RuntimeException("Unable to read:", e); } finally { try { bos.close(); } catch (Exception io) { io.printStackTrace(); } } return bos.toByteArray(); } }