Java Text File Read Line readLines(String filename)

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

Description

Read the lines of a file into a list of strings, with each line represented as its own 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.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.List;

import com.google.common.collect.Lists;

public class Main {
    /**/*  www  . j  a va 2 s  . c om*/
     * Read the lines of a file into a list of strings, with each line represented
     * as its own string.
     * 
     * @param filename
     * @return
     */
    public static List<String> readLines(String filename) {
        List<String> lines = Lists.newArrayList();
        try {
            BufferedReader in = new BufferedReader(new FileReader(filename));
            String line;
            while ((line = in.readLine()) != null) {
                // Ignore blank lines.
                if (line.trim().length() > 0) {
                    lines.add(line);
                }
            }
            in.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return lines;
    }
}

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 filename)