Here you can find the source of readTextFile(File f)
public static String readTextFile(File f) throws IOException
//package com.java2s; /* ===================================================================== * FileUtil -/* ww w .java 2 s . com*/ ------------------------------------------------------------------------- Copyright (c) 1991-2013 Andre Charles Legendre <andre.legendre@kalimasystems.org> Copyright other contributors as noted in the AUTHORS file. This file is part of JSPluginManager, the Javascript pluginManager for java This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This software 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 General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. * ===================================================================== */ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readTextFile(File f) throws IOException { StringBuffer buf = new StringBuffer(); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(f))); String inputLine; while ((inputLine = in.readLine()) != null) { buf.append(inputLine); buf.append('\n'); } in.close(); return buf.toString(); } }