Here you can find the source of fileToString(String fileName)
public static String fileToString(String fileName) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from www . ja v a 2 s. co m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ 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 fileToString(String fileName) throws IOException { System.gc(); File file = new File(fileName); FileInputStream fis = new FileInputStream(file); //BufferedInputStream bis = null; BufferedReader dis = new BufferedReader(new InputStreamReader(fis)); // dis.available() returns 0 if the file does not have more lines. StringBuffer buff = new StringBuffer(); String line = null; while ((line = dis.readLine()) != null) { buff.append(line); } // dispose all the resources after using them. fis.close(); dis.close(); return buff.toString(); } }