Java BufferedReader Read readFile(String fileName)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String fileName) throws FileNotFoundException, IOException 

Method Source Code


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

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

import java.io.Reader;

public class Main {
    public static String readFile(String fileName) throws FileNotFoundException, IOException {
        return readAll(new FileReader(fileName));
    }/*from w ww .  j  a  v a2 s . c  om*/

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

    public static String toString(Object[] array) {
        String s = "[Array ";
        if (array != null && array.length > 0) {
            s += array[0];
            for (int i = 1; i < array.length; i++)
                s += "," + array[i];
        }
        s += "]";

        return s;
    }

    public static String toString(boolean b) {
        return b ? "true" : "false";
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String filename)
  3. readFile(String fileName)
  4. readfile(String filename)
  5. readFile(String filename)
  6. readFile(String fileName)
  7. readFile(String filename)
  8. readFile(String filename)
  9. readFile(String fileName)