Here you can find the source of readFile(String fileName)
public static String readFile(String fileName)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.FileReader; public class Main { /**//w w w .java 2 s . c o m * Read the file and wirte the contents into the */ public static String readFile(String fileName) { BufferedReader bufferedReader = null; FileReader fileReader = null; String string = ""; try { fileReader = new FileReader(fileName); bufferedReader = new BufferedReader(fileReader); String temp = null; string = ""; temp = bufferedReader.readLine(); while (temp != null) { string += temp + "\r\n"; temp = bufferedReader.readLine(); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (bufferedReader != null) { bufferedReader.close(); } if (fileReader != null) { fileReader.close(); } } catch (Exception e) { e.printStackTrace(); } } return string; } }