Here you can find the source of readFileToString(String path, Charset charset)
public static String readFileToString(String path, Charset charset) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collection; import java.util.Iterator; import java.util.List; public class Main { public static String readFileToString(String path, Charset charset) throws IOException { List<String> lines = Files.readAllLines(Paths.get(path), charset); return join("", lines); }/*from w w w . j a v a 2 s . c o m*/ private static String join(String delim, Collection<?> col) { StringBuilder sb = new StringBuilder(); Iterator<?> iter = col.iterator(); if (iter.hasNext()) sb.append(iter.next().toString()); while (iter.hasNext()) { sb.append(delim); sb.append(iter.next().toString()); } return sb.toString(); } }