Here you can find the source of readTextFile(String filePath)
public static String readTextFile(String filePath)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { public static String readTextFile(String filePath) { String str = null;//from w w w. j a va 2 s . c om BufferedReader br = null; try { br = new BufferedReader(new FileReader(filePath)); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append("\n"); line = br.readLine(); } str = sb.toString(); } catch (IOException e) { e.printStackTrace(); } finally { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } return str; } }