Here you can find the source of fileToString(String fileName)
public static String fileToString(String fileName) throws Exception
//package com.java2s; /* //from ww w .j a v a 2 s . c o m Copyright (C) 2013 Raquel Pau and Albert Coroleu. Walkmod 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. Walkmod 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 Walkmod. If not, see <http://www.gnu.org/licenses/>.*/ import java.io.BufferedReader; import java.io.FileReader; public class Main { public static String fileToString(String fileName) throws Exception { StringBuffer result = new StringBuffer(); BufferedReader in = new BufferedReader(new FileReader(fileName)); char[] buffer = new char[1000]; int readedChars = 0; try { while ((readedChars = in.read(buffer)) > 0) { result.append(buffer, 0, readedChars); } } finally { in.close(); } return result.toString(); } }