Here you can find the source of readFile(String path, String charset)
public static String readFile(String path, String charset) throws IOException
//package com.java2s; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFile(String path) throws IOException { return readFile(path, "UTF-8"); }//from w w w .j a v a 2s. c o m public static String readFile(String path, String charset) throws IOException { FileInputStream fileStream = new FileInputStream(path); InputStreamReader inputStream = new InputStreamReader(fileStream, charset); try { StringBuilder sb = new StringBuilder(); int c; while ((c = inputStream.read()) != -1) { sb.append((char) c); } return sb.toString(); } finally { inputStream.close(); fileStream.close(); } } }