Here you can find the source of readFile(String fileName, String encoding)
public static String readFile(String fileName, String encoding)
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; public class Main { public static String readFile(String fileName) { try {//w ww . j a v a2 s . co m File adfile = new File(fileName); StringBuffer content = new StringBuffer(); if (adfile.isFile() && adfile.exists()) { InputStreamReader read = new InputStreamReader( new FileInputStream(adfile), Charset.defaultCharset()); BufferedReader in = new BufferedReader(read); String line1; while ((line1 = in.readLine()) != null) { content = content.append(line1 + ";"); } } return content.toString(); } catch (Exception e) { return null; } } public static String readFile(String fileName, String encoding) { try { File adfile = new File(fileName); StringBuffer content = new StringBuffer(); if (adfile.isFile() && adfile.exists()) { InputStreamReader read = new InputStreamReader( new FileInputStream(adfile), encoding); BufferedReader in = new BufferedReader(read); String line1; while ((line1 = in.readLine()) != null) { content = content.append(line1); } } return content.toString(); } catch (Exception e) { return null; } } }