Here you can find the source of readFileToString(String filename, Charset encoding)
public static String readFileToString(String filename, Charset encoding) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; public class Main { private static final int BUFFER_SIZE = 4 * 1024; public static String readFileToString(String filename, Charset encoding) throws IOException { return readStreamToString(new FileInputStream(filename), encoding); }/*w ww . ja va 2 s . co m*/ public static String readFileToString(File file, Charset encoding) throws IOException { return readStreamToString(new FileInputStream(file), encoding); } public static String readStreamToString(InputStream stream, Charset encoding) throws IOException { StringBuilder builder = new StringBuilder(); InputStreamReader reader = new InputStreamReader(stream, encoding); char[] buffer = new char[BUFFER_SIZE]; int length; while ((length = reader.read(buffer)) != -1) { builder.append(buffer, 0, length); } reader.close(); return builder.toString(); } }