Here you can find the source of getFileContents(File file)
public static String getFileContents(File file) throws Exception
//package com.java2s; /******************************************************************************* * Copyright (c) 2008 The University of York. * 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 * /* w ww.j ava 2 s . co m*/ * Contributors: * Dimitrios Kolovos - initial API and implementation ******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.Collection; import java.util.LinkedList; import java.util.List; public class Main { public static String getFileContents(File file) throws Exception { final StringBuffer buffer = new StringBuffer(); final String lineSeparator = System.getProperty("line.separator"); for (String line : getFileLineContents(file)) { buffer.append(line); buffer.append(lineSeparator); } return buffer.toString(); } public static Collection<String> getFileLineContents(File file) throws Exception { final BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); try { final List<String> lines = new LinkedList<String>(); String line = bufferedReader.readLine(); while (line != null) { lines.add(line); line = bufferedReader.readLine(); } return lines; } finally { bufferedReader.close(); } } }