Here you can find the source of readFile(File file)
public static String readFile(File file)
//package com.java2s; /*/*from www. j a v a 2 s . c o m*/ * Copyright (c) 2005 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: * IBM - initial API and implementation * * $Id: BuildUtil.java,v 1.3 2007/02/22 08:40:26 asobolev Exp $ */ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { public static String readFile(File file) { StringBuffer stringBuffer = new StringBuffer(); try { BufferedReader in = new BufferedReader(new FileReader(file)); try { char[] buffer = new char[1024]; int size = 0; while ((size = in.read(buffer)) > -1) { stringBuffer.append(buffer, 0, size); } } finally { if (in != null) { in.close(); } } } catch (IOException exception) { throw new RuntimeException(exception); } return stringBuffer.toString(); } }