Here you can find the source of readTextFile(File file, String encoding)
public static String readTextFile(File file, String encoding) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static String readTextFile(File file) throws FileNotFoundException, IOException { return readTextFile(file, null); }/*from ww w . j a v a 2 s . c o m*/ public static String readTextFile(File file, String encoding) throws FileNotFoundException, IOException { BufferedReader br; if (encoding == null) { br = new BufferedReader(new FileReader(file)); } else if (!encoding.isEmpty()) { br = new BufferedReader(new FileReader(file)); } else { br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding)); } try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(String.format("%s%n", line)); line = br.readLine(); } return sb.toString(); } finally { br.close(); } } }