Here you can find the source of readFile(File file)
public static String readFile(File file) throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; public class Main { private static final String ENCODING = "UTF-8"; public static String readFile(File file) throws Exception { StringBuilder result = new StringBuilder(); BufferedReader in = null; try {// w w w. j a va 2 s. c o m in = new BufferedReader(new InputStreamReader( new FileInputStream(file), ENCODING)); String line; while ((line = in.readLine()) != null) { result.append(line); result.append("\n"); } } catch (Exception e) { throw e; } finally { in.close(); } return result.toString(); } }