Java BufferedReader Read readFile(File f)

Here you can find the source of readFile(File f)

Description

Reads in a file.

License

Open Source License

Parameter

Parameter Description
f file to read in

Exception

Parameter Description
IOException if an IO error occurs

Return

the content of the file in a string

Declaration

public static String readFile(File f) throws IOException 

Method Source Code


//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();
    }
}

Related

  1. loadVocab(String vocabFilePath, double factor)
  2. loadWaypoints(File inFile)
  3. loadXML(String fileName)
  4. loadXMLDocumentFromClasspath(String resourcePath)
  5. loadY(InputStream filePath)
  6. readFile(File f)
  7. readFile(File f)
  8. readFile(File f)
  9. readFile(File f)