Here you can find the source of getFileContents(File f)
public static String getFileContents(File f)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007 Red Hat, Inc.//from www.j av a2s . c o m * Distributed under license by Red Hat, Inc. All rights reserved. * This program is 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: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { public static String getFileContents(File f) { try { BufferedReader r = new BufferedReader(new FileReader(f)); StringBuffer contents = new StringBuffer(); int c = r.read(); while (c != -1) { contents.append((char) c); c = r.read(); } r.close(); return contents.toString(); } catch (IOException ioe) { return null; } } }