Java BufferedReader Read readFile(File file)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(File file) throws FileNotFoundException,
            IOException 

Method Source Code

//package com.java2s;
// Clark & Parsia, LLC parts of this source code are available under the terms of the Affero General Public License v3.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import java.io.IOException;

import java.io.Reader;

public class Main {
    public static String readFile(File file) throws FileNotFoundException,
            IOException {/*w w w .  j a  va 2s  .  c  om*/
        return readAll(new FileReader(file));
    }

    public static String readFile(String fileName)
            throws FileNotFoundException, IOException {
        return readAll(new FileReader(fileName));
    }

    public static String readAll(Reader reader) throws IOException {
        StringBuffer buffer = new StringBuffer();

        BufferedReader in = new BufferedReader(reader);
        int ch;
        while ((ch = in.read()) > -1) {
            buffer.append((char) ch);
        }
        in.close();

        return buffer.toString();
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)