Here you can find the source of readFile(File file)
public static String readFile(File file)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFile(String file) { return readFile(file, null); }// w w w. ja v a 2 s . com public static String readFile(String file, String lineBreak) { File f = new File(file); return readFile(f, lineBreak); } public static String readFile(File file) { return readFile(file, null); } public static String readFile(File file, String lineBreak) { String lb = lineBreak == null ? "\r\n" : lineBreak; BufferedReader br = null; StringBuilder buf = new StringBuilder(); try { br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String line = null; while ((line = br.readLine()) != null) { buf.append(line).append(lb); } } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return buf.toString(); } }