Java Text File Read Line readLines(String filename)

Here you can find the source of readLines(String filename)

Description

read Lines

License

Apache License

Declaration

public static ArrayList<String> readLines(String filename) 

Method Source Code


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

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> readLines(String filename) {

        File f = new File(filename);

        if (!f.exists()) {

            try {
                f.createNewFile();//w  ww .  j  av  a2  s .  com
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        try {
            BufferedReader br = new BufferedReader(new FileReader(filename));

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

            br.close();

            return lines;

        } catch (IOException localIOException) {
            localIOException.printStackTrace();
        }

        return null;
    }
}

Related

  1. readLines(String fileName)
  2. readLines(String filename)
  3. readLines(String fileName)
  4. readLines(String filename)
  5. readLines(String filename)
  6. readLines(String fileName)
  7. readLines(String filePath)
  8. readLines(String filePath)
  9. readLines(String filePath)