Here you can find the source of getFileContentAsBytes(String fileName)
static public byte[] getFileContentAsBytes(String fileName) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { static public byte[] getFileContentAsBytes(String fileName) throws Exception { FileInputStream is = new FileInputStream(fileName); byte[] data = getStreamContentAsBytes(is); is.close();/*from www. j a va2s . c o m*/ return data; } static public byte[] getStreamContentAsBytes(InputStream is) throws IOException { BufferedInputStream buffer = new BufferedInputStream(is); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] data = new byte[4912]; int available = -1; while ((available = buffer.read(data)) > -1) { output.write(data, 0, available); } is.close(); return output.toByteArray(); } static public byte[] getStreamContentAsBytes(InputStream is, int maxRead) throws IOException { BufferedInputStream buffer = new BufferedInputStream(is); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] data = new byte[4912]; int available = -1, read = 0; while ((available = buffer.read(data)) > -1 && read < maxRead) { if (maxRead - read < available) available = maxRead - read; output.write(data, 0, available); read += available; } return output.toByteArray(); } }