Here you can find the source of readFile(File file)
public static String readFile(File file) throws UnsupportedEncodingException, FileNotFoundException, IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; public class Main { private static final int BUFFER = 2048; public static String readFile(File file) throws UnsupportedEncodingException, FileNotFoundException, IOException { final char[] buffer = new char[BUFFER]; final StringBuilder out = new StringBuilder(); try (final Reader in = new InputStreamReader(new FileInputStream(file), "UTF-8")) { return readFromStream(buffer, out, in); }/*from ww w.j a va 2 s . c o m*/ } public static String readFromStream(final char[] buffer, final StringBuilder out, final Reader in) throws IOException { while (true) { final int read = in.read(buffer, 0, BUFFER); if (read <= 0) { break; } out.append(buffer, 0, read); } return out.toString(); } }