Here you can find the source of readFileAsBinary(File file)
public static String readFileAsBinary(File file) throws IOException
//package com.java2s; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static String readFileAsBinary(File file) throws IOException { StringBuffer stringBuffer = new StringBuffer(); BufferedInputStream input = null; try {//from www . j a va 2 s.c om input = new BufferedInputStream(new FileInputStream(file)); int read = 0; byte[] buffer = new byte[1024]; while ((read = input.read(buffer)) != -1) stringBuffer.append(read); return stringBuffer.toString(); } finally { if (input != null) input.close(); } } }