Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
file | The file to read. |
Parameter | Description |
---|---|
IOException | If the file is not readable. |
public static String readFile(File file) throws IOException
//package com.java2s; /**/*from w w w .j a va 2s .c om*/ * @author Charles McGarvey * The TopCoder Arena editor plug-in providing support for Vim. * * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. */ import java.io.*; public class Main { /** * Simply read a file's contents into a string object. * @param file The file to read. * @return The contents of the file. * @throws IOException If the file is not readable. */ public static String readFile(File file) throws IOException { StringBuilder text = new StringBuilder(); BufferedReader reader = new BufferedReader(new FileReader(file.getPath())); try { String line = null; while ((line = reader.readLine()) != null) { text.append(line + System.getProperty("line.separator")); } } finally { reader.close(); } return text.toString(); } }