Here you can find the source of readFile(String fileName)
@SuppressWarnings("resource") public static String readFile(String fileName)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { @SuppressWarnings("resource") public static String readFile(String fileName) { try {//www . j a v a 2s . c om File f = new File(fileName); if (!f.exists() || f.isDirectory()) throw new IOException("File does not exist! " + f); StringBuilder model = new StringBuilder(100); BufferedReader bfr = null; bfr = new BufferedReader(new FileReader(f)); String line = null; while ((line = bfr.readLine()) != null) { model.append(line + "\n"); } model.delete(model.length() - 1, model.length()); return model.toString(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } return null; } }