Java BufferedReader Read readFile(String filename)

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

Description

read File

License

Apache License

Declaration

public static String readFile(String filename) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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) {
        try {//from w w  w. j av  a 2 s . co  m
            return readReader(new FileReader(file));
        } catch (FileNotFoundException e) {
        }
        return null;
    }

    public static String readFile(String filename) {
        return readFile(new File(filename));
    }

    public static String readReader(Reader reader) {
        String content = "";
        try {
            BufferedReader bufferedReader = new BufferedReader(reader);
            while (true) {
                String line;
                line = bufferedReader.readLine();
                if (line == null)
                    return content;
                content += line + "\n";
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

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)