Here you can find the source of readFile(String filename)
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.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; public class Main { public static String readFile(File file) { try {//from w w w. j av a 2 s . co m return readReader(new FileReader(file)); } catch (FileNotFoundException e) { } return null; } public static String readFile(String filename) { return readFile(new File(filename)); } public static String readReader(Reader reader) { String content = ""; try { BufferedReader bufferedReader = new BufferedReader(reader); while (true) { String line; line = bufferedReader.readLine(); if (line == null) return content; content += line + "\n"; } } catch (IOException e) { e.printStackTrace(); } return null; } }