Java InputStreamReader Read readFile(File filename)

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

Description

read File

License

Open Source License

Declaration

public synchronized static String readFile(File 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.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public synchronized static String readFile(String filename) throws IOException {
        return readFile(new File(filename));
    }/*from  w  w  w  . jav  a  2 s . c  om*/

    public synchronized static String readFile(File filename) throws IOException {

        StringBuilder result = new StringBuilder();

        InputStream ips = new FileInputStream(filename);
        InputStreamReader ipsr = new InputStreamReader(ips);
        try (BufferedReader br = new BufferedReader(ipsr)) {
            String line;
            while ((line = br.readLine()) != null) {
                result.append(line).append("\n");
            }
        }

        return result.toString();
    }
}

Related

  1. readFile(File file, String default_encoding)
  2. readFile(File file, String encoding)
  3. readFile(File file, String encoding)
  4. readFile(File file, String encoding)
  5. readFile(File file, String encoding)
  6. readFile(File path)
  7. readFile(File resultFile)
  8. readFile(File target)
  9. readFile(FileInputStream file)