Here you can find the source of readFile(String fileName)
public static String readFile(String fileName)
//package com.java2s; import java.io.FileInputStream; import java.io.IOException; public class Main { public static String readFile(String fileName) { StringBuffer sbuf = new StringBuffer(); FileInputStream reader = null; try {//from w w w . j a va 2s . c o m byte[] buf = new byte[2048]; reader = new FileInputStream(fileName); int read = -1; while ((read = reader.read(buf)) != -1) { sbuf.append(new String(buf, 0, read)); } } catch (Exception ee) { ee.printStackTrace(); return null; } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } return sbuf.toString(); } public static String toString(String str, char separator, int radix) { byte[] value = str.getBytes(); int digits = (int) (Math.round((float) Math.log(256) / Math.log(radix))); StringBuffer buf = new StringBuffer(value.length * (digits + 1)); for (int i = 0; i < value.length; i++) { if (i > 0) { buf.append(separator); } int v = (value[i] & 0xFF); String val = Integer.toString(v, radix); for (int j = 0; j < digits - val.length(); j++) { buf.append('0'); } buf.append(val); } return buf.toString(); } }