Java BufferedReader Read readFile(String fileNm)

Here you can find the source of readFile(String fileNm)

Description

read File

License

Open Source License

Declaration

public static ArrayList<String> readFile(String fileNm) 

Method Source Code


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

import java.io.BufferedReader;

import java.io.File;
import java.io.FileReader;

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> readFile(String fileNm) {
        ArrayList<String> lines = null;

        FileReader fr = null;//ww  w  .j av  a2s. com
        BufferedReader br = null;
        try {
            fr = new FileReader(new File(fileNm));
            br = new BufferedReader(fr);
            lines = new ArrayList<String>();

            String line = null;
            while ((line = br.readLine()) != null) {
                lines.add(line);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fr != null)
                try {
                    fr.close();
                } catch (Exception ex) {
                }
            ;
            if (br != null)
                try {
                    br.close();
                } catch (Exception ex) {
                }
            ;
        }

        return lines;
    }
}

Related

  1. readFile(String filename, boolean print)
  2. readFile(String filename, boolean skipEmptyLine)
  3. readFile(String fileName, String basePath)
  4. readFile(String fileName, String commentFlag)
  5. readFile(String fileName, String commentFlag)
  6. readFile(String filePath)
  7. readFile(String filePath)
  8. readFile(String filePath)
  9. readFile(String filePath)