Here you can find the source of fileToString(String file)
public static String fileToString(String file) throws IOException
//package com.java2s; /*//from ww w . j av a 2 s . c o m Copyright (C) 2010 Nick Crafford <nickcrafford@gmail.com> This file is part of dbmojo dbmojo 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 3 of the License, or (at your option) any later version. dbmojo 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. You should have received a copy of the GNU General Public License along with dbmojo. If not, see <http://www.gnu.org/licenses/>. */ import java.io.*; public class Main { /** Read a file into a String */ public static String fileToString(String file) throws IOException { StringBuilder lines = new StringBuilder(); FileReader fileReader = null; BufferedReader bufferedReader = null; String line = null; try { fileReader = new FileReader(file); bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { lines.append(line); } } finally { if (bufferedReader != null) { bufferedReader.close(); } if (fileReader != null) { fileReader.close(); } } return lines.toString(); } }