Here you can find the source of fileToString(File file)
public static String fileToString(File file) throws Exception
//package com.java2s; /** // w w w. j a va 2 s . c om * Author: anthony.fodor@gmail.com * This code is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version, * provided that any use properly credits the author. * This program 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 General Public License for more details at http://www.gnu.org * * */ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.StringWriter; public class Main { public static String fileToString(File file) throws Exception { BufferedReader reader = new BufferedReader(new FileReader(file)); StringWriter writer = new StringWriter(); char[] c = new char[2048]; int bytesRead; while ((bytesRead = reader.read(c, 0, c.length)) != -1) writer.write(c, 0, bytesRead); writer.close(); reader.close(); return writer.toString(); } }