Here you can find the source of readFile(File file, String encoding)
public static String readFile(File file, String encoding)
//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 { public static String readFile(String fileName) { String fileContent = ""; try {//w ww .java2 s .co m File f = new File(fileName); if (f.isFile() && f.exists()) { InputStreamReader read = new InputStreamReader(new FileInputStream(f), "utf-8"); BufferedReader reader = new BufferedReader(read); String line; while ((line = reader.readLine()) != null) { fileContent += line; } read.close(); } } catch (Exception e) { e.printStackTrace(); } return fileContent; } public static String readFile(File file, String encoding) { String fileContent = ""; try { if (file.isFile() && file.exists()) { InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding); BufferedReader reader = new BufferedReader(read); String line; while ((line = reader.readLine()) != null) { fileContent += line; } read.close(); } } catch (Exception e) { e.printStackTrace(); } return fileContent; } public static String readFile(String fileName, String encoding) { File file = new File(fileName); return readFile(file, encoding); } }