Here you can find the source of fileToString(File file, String charsetName)
public static String fileToString(File file, String charsetName) throws IOException
//package com.java2s; import java.io.*; public class Main { public static String fileToString(File file, String charsetName) throws IOException { FileInputStream in = new FileInputStream(file); try {/*from w w w . j av a 2s. c om*/ return allToString(new InputStreamReader(in, charsetName)); } finally { in.close(); } } public static String allToString(InputStream is, String charsetName) throws IOException { if (is instanceof ByteArrayInputStream) { byte[] bytes = new byte[is.available()]; //noinspection ResultOfMethodCallIgnored is.read(bytes); return new String(bytes, charsetName); } return allToString(new InputStreamReader(is, charsetName)); } public static String allToString(Reader in) throws IOException { StringBuilder buf = new StringBuilder(); int size = 16384; char[] str = new char[size]; int n; while ((n = in.read(str, 0, size)) > 0) { buf.append(str, 0, n); } return buf.toString(); } }