Java InputStreamReader Read readFile(String filename, boolean addEOL)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String filename, boolean addEOL) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {
    public static String readFile(String filename, boolean addEOL) throws IOException {

        StringBuffer buf = new StringBuffer();
        BufferedReader bufReader = null;
        try {//  w w  w .  j  av a 2s . c o  m
            FileInputStream fis = new FileInputStream(filename);
            bufReader = new BufferedReader(new InputStreamReader(fis));
            String line = "";
            while ((line = bufReader.readLine()) != null) {
                buf.append(line);
                // possibly add EOL char to each line
                if (addEOL)
                    buf.append('\n');
            }

            // System.out.println(buf);
        } finally {
            if (bufReader != null)
                bufReader.close();
        }
        // may be empty string if an error occurred
        return buf.toString();
    }
}

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, Class clazz)
  7. readFile(String fileName, String characterEncoding)
  8. readFile(String fileName, String characterEncoding)
  9. readFile(String fileName, String characterEncoding)