Here you can find the source of readTextFile(String realPath)
public static String readTextFile(String realPath) throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; public class Main { public static String readTextFile(String realPath) throws Exception { File file = new File(realPath); if (!file.exists()) { System.out.println("File not exist!"); return null; }/* w ww. j a va 2 s. c o m*/ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(realPath), "UTF-8")); String temp = ""; String txt = ""; while ((temp = br.readLine()) != null) { txt += temp; } br.close(); return txt; } }