Here you can find the source of readFileToStr(String fn, String charset)
public static String readFileToStr(String fn, String charset)
//package com.java2s; //License from project: Apache License import java.io.FileInputStream; public class Main { public static String readFileToStr(String fn) { return readFileToStr(fn, null); }/*w w w . ja va2 s. c o m*/ public static String readFileToStr(String fn, String charset) { FileInputStream in = null; try { in = new FileInputStream(fn); try { byte[] buf = new byte[in.available()]; int r = in.read(buf); return charset == null ? new String(buf, 0, r) : new String(buf, 0, r, charset); } finally { in.close(); } } catch (Exception e) { // e.printStackTrace(); } return ""; } }