Here you can find the source of readTextFile(File file)
public static String readTextFile(File file) throws IOException
//package com.java2s; import java.io.*; public class Main { public static String readTextFile(File file) throws IOException { String text = null;/*from ww w. j a v a2 s . c o m*/ InputStream is = null; if (null != file) { try { is = new FileInputStream(file); text = readTextInputStream(is); ; } finally { if (is != null) { is.close(); } } } return text; } public static String readTextInputStream(InputStream is) throws IOException { if (null == is) return null; StringBuffer strbuffer = new StringBuffer(); String line; BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(is)); while ((line = reader.readLine()) != null) { strbuffer.append(line).append("\r\n"); } } finally { if (reader != null) { reader.close(); } } return strbuffer.toString(); } }