Here you can find the source of readFile(String path)
public static String readFile(String path) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static String readFile(String path) throws IOException { FileInputStream in = new FileInputStream(path); String s = readStreamUTF8(in); in.close();// w w w.j av a 2s . c o m return s; } public static String readStreamUTF8(InputStream in) throws IOException { if (in == null) throw new IOException("in == null"); byte[] data = readStream(in); return new String(data, "utf-8"); } public static byte[] readStream(InputStream in) throws IOException { if (in == null) throw new IOException("in == null"); ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = in.read(buffer)) != -1) { bout.write(buffer, 0, len); } in.close(); return bout.toByteArray(); } }