Here you can find the source of readFile(String fileName, String charSet)
public static String readFile(String fileName, String charSet)
//package com.java2s; //License from project: Open Source License import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFile(String fileName, String charSet) { InputStreamReader in = null; try {//from ww w . j a va 2 s .co m in = new InputStreamReader(new FileInputStream(fileName), charSet); StringBuffer content = new StringBuffer(); int line = -1; while ((line = in.read()) != -1) { content.append((char) line); } return content.toString(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; } }