Here you can find the source of readFile(File f)
Parameter | Description |
---|---|
f | file to read in |
Parameter | Description |
---|---|
IOException | if an IO error occurs |
public static String readFile(File f) throws IOException
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /**/* w w w .j a v a2s . com*/ * Reads in a file. * * @param f * file to read in * @return the content of the file in a string * @throws IOException * if an IO error occurs */ public static String readFile(File f) throws IOException { BufferedReader r = new BufferedReader(new FileReader(f)); StringBuilder builder = new StringBuilder(); int c; while ((c = r.read()) != -1) { builder.append((char) c); } return builder.toString(); } }