Here you can find the source of readFileContents(File file, Charset charset)
public static String readFileContents(File file, Charset charset) throws Exception
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; public class Main { public static String readFileContents(File file) throws Exception { return readFileContents(file, Charset.forName("UTF-8")); }/* w ww .ja v a 2 s. com*/ public static String readFileContents(File file, Charset charset) throws Exception { BufferedReader br = null; StringBuilder sb = null; String line; if (file != null && charset != null) { if (file.exists()) { try { sb = new StringBuilder(); br = Files.newBufferedReader(Paths.get(file.getPath()), charset); while ((line = br.readLine()) != null) { sb.append(line); } br.close(); return sb.toString(); } catch (IOException ex) { throw ex; } } throw new Exception("The file does not exist."); } throw new Exception("Invalid or incomplete parameters."); } }