Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
file | file to be read |
Parameter | Description |
---|---|
IOException | an exception |
static public String readFile(File file) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2011. 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 * //from www. ja v a 2s . c om * Contributors: * Fizer Khan, Yasmine - initial API and implementation *******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /** * Read content from file * * @param file * file to be read * @return file contents * @throws IOException */ static public String readFile(File file) throws IOException { StringBuilder contents = new StringBuilder(); BufferedReader input = new BufferedReader(new FileReader(file)); try { String line = null; while ((line = input.readLine()) != null) { contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } return contents.toString(); } }