Here you can find the source of readFile(String fileName)
public static String readFile(String fileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static String readFile(String fileName) throws IOException { if (fileName == null) throw new IOException("filename is null"); FileReader fr = new FileReader(fileName); BufferedReader br = new BufferedReader(fr); StringBuilder buffer = new StringBuilder(); String nextLine;//from w w w . j av a2 s . c om while ((nextLine = br.readLine()) != null) buffer.append(nextLine).append("\n"); //Remove final newline if (buffer.length() > 0 && buffer.charAt(buffer.length() - 1) == '\n') buffer.deleteCharAt(buffer.length() - 1); br.close(); fr.close(); return buffer.toString(); } }