Here you can find the source of readTextFile(String filePath)
public static String readTextFile(String filePath)
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class Main { public static String readTextFile(String filePath) { File textFile = new File(filePath); BufferedReader in = null; String text = null;/*from w w w. j ava 2s . co m*/ StringBuilder allText = new StringBuilder(""); try { in = new BufferedReader(new FileReader(textFile)); while ((text = in.readLine()) != null) { allText.append(text).append("\n"); } } catch (Exception e) { e.printStackTrace(); try { if (in != null) { in.close(); } } catch (Exception ee) { ee.printStackTrace(); } } finally { try { if (in != null) { in.close(); } } catch (Exception e) { e.printStackTrace(); } } return allText.toString(); } }