Java InputStreamReader Create readTextFile(File file)

Here you can find the source of readTextFile(File file)

Description

read Text File

License

Open Source License

Declaration

public static String readTextFile(File file) 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 static String readTextFile(File file) throws IOException {
        String text = null;/*w  w  w.  j  a  va 2 s. c  om*/
        InputStream is = null;
        try {
            is = new FileInputStream(file);
            text = readTextInputStream(is);
        } finally {
            if (is != null) {
                is.close();
            }
        }
        return text;
    }

    public static String readTextInputStream(InputStream is) throws IOException {
        StringBuffer strbuffer = new StringBuffer();
        String line;
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(is));
            while ((line = reader.readLine()) != null) {
                strbuffer.append(line).append("\r\n");
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
        return strbuffer.toString();
    }
}

Related

  1. readTextFile(File f)
  2. readTextFile(File f)
  3. readTextFile(File f)
  4. readTextFile(File f, int maxNumLines)
  5. readTextFile(File file)
  6. readTextFile(File file, String charsetName)
  7. readTextFile(File fromFile)
  8. readTextFile(File inputFile)
  9. readTextFile(File path)