Java InputStreamReader Create readTextFile(String fileName)

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

Description

read Text File

License

Open Source License

Declaration

public static ArrayList<String> readTextFile(String fileName) 

Method Source Code

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

import java.io.*;

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> readTextFile(String fileName) {
        ArrayList<String> strs = new ArrayList<String>();
        try {//  w ww . j  a  va  2  s  .c o  m
            BufferedReader bin = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileName))));
            String line;
            while ((line = bin.readLine()) != null) {
                line = line.trim();
                if (line.length() != 0)
                    strs.add(line);
            }
            if (bin != null) {
                bin.close();
            }
        } catch (IOException e) {
            System.err.println("Error when processing " + fileName);
            e.printStackTrace(System.err);
        }
        return strs;
    }
}

Related

  1. readTextFile(final File f)
  2. readTextFile(final File file)
  3. ReadTextFile(InputStream is)
  4. readTextFile(java.io.File file)
  5. readTextFile(Reader reader)
  6. readTextFile(String filename, int maxNumLines, boolean startAtBeginning)
  7. readTextFile(String filePath, String charset)
  8. readTextFile(String fullPathFilename)
  9. readTextFile(String realPath)