Here you can find the source of readFile(String fileName)
public static String readFile(String fileName)
//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 {/*from ww w . ja va 2 s .c o 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; } } }