Java BufferedReader Read readFile(final String fileName)

Here you can find the source of readFile(final String fileName)

Description

read File

License

Open Source License

Declaration

public static String readFile(final String fileName) throws IOException 

Method Source Code


//package com.java2s;
// The MIT License

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import java.io.Reader;

public class Main {
    public static String readFile(final String fileName) throws IOException {
        return readAll(new FileReader(fileName));
    }//from  w  w w. ja v a  2 s  .  com

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

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

Related

  1. readFile(final File file)
  2. readFile(final File file)
  3. readFile(final File file)
  4. readFile(final File paramFile, final boolean paramWhitespaces)
  5. readFile(final String file)
  6. readFile(final String filename)
  7. readFile(final String fileName)
  8. readFile(final String filePath)
  9. readFile(final String name)