Java InputStreamReader Create readTextFile(String realPath)

Here you can find the source of readTextFile(String realPath)

Description

read Text File

License

Apache License

Declaration

public static String readTextFile(String realPath) throws Exception 

Method Source Code

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

import java.io.BufferedReader;

import java.io.File;
import java.io.FileInputStream;

import java.io.InputStreamReader;

public class Main {
    public static String readTextFile(String realPath) throws Exception {
        File file = new File(realPath);
        if (!file.exists()) {
            System.out.println("File not exist!");
            return null;
        }/* w  ww.  j  a  va  2 s. c o m*/
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(realPath), "UTF-8"));
        String temp = "";
        String txt = "";
        while ((temp = br.readLine()) != null) {
            txt += temp;
        }
        br.close();
        return txt;
    }
}

Related

  1. readTextFile(Reader reader)
  2. readTextFile(String fileName)
  3. readTextFile(String filename, int maxNumLines, boolean startAtBeginning)
  4. readTextFile(String filePath, String charset)
  5. readTextFile(String fullPathFilename)
  6. readTextFileAsStringArray(final File file, final String charSet)