Java Text File Read Line readLines(String filename)

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

Description

Just return each line of the file as String

License

Open Source License

Parameter

Parameter Description
filename a parameter

Declaration

public static List<String> readLines(String filename) 

Method Source Code


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

import java.io.*;
import java.util.*;

public class Main {
    /**/*from www  .  j  av  a2  s  .co m*/
     * Just return each line of the file as String
     * 
     * @param filename
     * @return
     */
    public static List<String> readLines(String filename) {
        ArrayList<String> retval = new ArrayList<String>();
        try {
            BufferedReader in = new BufferedReader(new FileReader(filename));
            String curLine = in.readLine();
            while (curLine != null) {
                retval.add(curLine.trim());
                curLine = in.readLine();
            }
            return retval;
        } catch (IOException ioe) {
            System.out.println(String.format("Bad file(name): %s\n", ioe.toString()));
            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 filename)
  8. readLines(String fileName)
  9. readLines(String filePath)