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 IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source 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(String filename) throws IOException {
        return readFile(new File(filename));
    }//from w ww  .  j av  a  2s  .c o  m

    public static String readFile(File file) throws IOException {
        Reader inputScript = getFileReader(file);
        BufferedReader br = new BufferedReader(inputScript);
        String line;
        StringBuffer sb = new StringBuffer();

        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
        }

        br.close();
        return sb.toString();
    }

    public static Reader getFileReader(String filename) throws FileNotFoundException {
        return getFileReader(new File(filename));
    }

    public static Reader getFileReader(File file) throws FileNotFoundException {
        return new FileReader(file);
    }
}

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)