Java Text File Read by Encoding readTextFile(String sFileName, String sEncode)

Here you can find the source of readTextFile(String sFileName, String sEncode)

Description

read Text File

License

Open Source License

Declaration

private static String readTextFile(String sFileName, String sEncode) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

import java.io.InputStreamReader;

public class Main {
    private static String readTextFile(String sFileName, String sEncode) {
        StringBuffer sbStr = new StringBuffer();
        try {/*from  ww w . j ava2  s  .  c  o  m*/
            File ff = new File(sFileName);
            InputStreamReader read = new InputStreamReader(
                    new FileInputStream(ff), sEncode);
            BufferedReader ins = new BufferedReader(read);
            String dataLine = "";
            while (null != (dataLine = ins.readLine())) {
                sbStr.append(dataLine);
                // sbStr.append("/r/n");
            }
            ins.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sbStr.toString();
    }
}

Related

  1. readTextFile(File file, String encoding)
  2. readTextFile(File path, String encoding)
  3. readTextFile(InputStream in, String encoding)
  4. readTextFile(InputStream in, String encoding)
  5. readTextFile(java.io.File file, String encoding)