Here you can find the source of readFile(final File file)
protected static String readFile(final File file) throws IOException
//package com.java2s; // The MIT License import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.Reader; public class Main { protected static String readFile(final File file) throws IOException { StringBuilder stringBuilder = new StringBuilder(); FileReader reader = null; try {//w w w .j a v a 2s . co m reader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(reader); while (bufferedReader.ready()) { stringBuilder.append(bufferedReader.readLine()); stringBuilder.append(System.getProperty("line.separator")); } bufferedReader.close(); } catch (IOException e) { throw e; // TODO: remove the IOE from method signature and throw a new // exception extending runtime } finally { closeQuietly(reader); } return stringBuilder.toString(); } public static void closeQuietly(Reader reader) { if (null != reader) { try { reader.close(); } catch (Exception e) { // ignore all exceptions } } } public static void closeQuietly(InputStream inputStream) { if (null != inputStream) { try { inputStream.close(); } catch (Exception e) { // ignore all exceptions } } } }