Java InputStreamReader Read readFile(String fileName, String charSet)

Here you can find the source of readFile(String fileName, String charSet)

Description

read File

License

Open Source License

Declaration

public static String readFile(String fileName, String charSet) 

Method Source Code

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

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {

    public static String readFile(String fileName, String charSet) {
        InputStreamReader in = null;
        try {//from   ww  w  . j  a  va  2  s  .co m
            in = new InputStreamReader(new FileInputStream(fileName), charSet);

            StringBuffer content = new StringBuffer();

            int line = -1;
            while ((line = in.read()) != -1) {
                content.append((char) line);
            }
            return content.toString();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

Related

  1. readFile(String filename, boolean addEOL)
  2. readFile(String fileName, Class clazz)
  3. readFile(String fileName, String characterEncoding)
  4. readFile(String fileName, String characterEncoding)
  5. readFile(String fileName, String characterEncoding)
  6. readFile(String fileName, String coloredLineIndicator, boolean useSections, boolean isXML)
  7. readFile(String filename1)
  8. readFile(String fileNm)
  9. readFile(String filePath)