Here you can find the source of readFile(File f)
public static String readFile(File f) throws IOException
//package com.java2s; /*//from ww w. j a v a2 s. c om Copyright 2012 Daniel Gonzalez Pe?a, Osvaldo Gra?a This file is part of the bicycle Project. bicycle Project is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. bicycle Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details. You should have received a copy of the GNU Lesser Public License along with bicycle Project. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Main { public static String readFile(File f) throws IOException { StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader(new FileReader(f)); boolean first = true; for (String line = reader.readLine(); line != null; line = reader.readLine(), first = false) { if (!first) builder.append("\n"); builder.append(line); } return builder.toString(); } public static void append(File f, String s) throws IOException { FileWriter writer = new FileWriter(f); writer.write(s); writer.close(); } }