Here you can find the source of readTextFile(String fileName)
public static String readTextFile(String fileName)
//package com.java2s; import java.io.*; public class Main { public static String readTextFile(String fileName) { try {//from ww w. j a v a 2s .c om BufferedReader in = new BufferedReader(new FileReader(fileName)); String line, fileContents; fileContents = null; while ((line = in.readLine()) != null) { if (fileContents == null) fileContents = line + "\n"; else fileContents = fileContents + line + "\n"; } in.close(); return fileContents; } catch (Exception e) { return e.getMessage(); } } }