Here you can find the source of readFile(File f)
public static String readFile(File f) throws IOException
//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 { public static String readFile(File f) throws IOException { BufferedReader br = null; try {//from w w w . j a v a 2 s .com br = new BufferedReader(new FileReader(f)); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); line = br.readLine(); if (line != null) { sb.append("\n"); } } return sb.toString(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { throw (e); } } } } }