Here you can find the source of load(File file, Charset charset)
public static String load(File file, Charset charset) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.charset.Charset; public class Main { private static final int BUFFER_SIZE = 32768; public static String load(File file, Charset charset) throws IOException { long length = file.length(); if (length > Integer.MAX_VALUE) { throw new UnsupportedOperationException("File too large (" + length + " bytes)"); }/* ww w . j ava 2 s.co m*/ StringBuilder sb = new StringBuilder((int) length); try (InputStreamReader in = new InputStreamReader(new BufferedInputStream(new FileInputStream(file)), charset)) { char[] buffer = new char[BUFFER_SIZE]; int read; while ((read = in.read(buffer)) != -1) { sb.append(buffer, 0, read); } } return sb.toString(); } public static String load(InputStream inputStream, Charset charset) throws IOException { StringBuilder sb = new StringBuilder(); try (InputStreamReader in = new InputStreamReader(new BufferedInputStream(inputStream), charset)) { char[] buffer = new char[BUFFER_SIZE]; int read; while ((read = in.read(buffer)) != -1) { sb.append(buffer, 0, read); } } return sb.toString(); } }