Java BufferedReader Read loadLines(String file)

Here you can find the source of loadLines(String file)

Description

Load the lines from a local text file into a list of strings.

License

Open Source License

Parameter

Parameter Description
file path of the file whose line must be loaded

Return

the list of lines

Declaration

public static List<String> loadLines(String file) 

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.ArrayList;
import java.util.List;

public class Main {
    /**/* w  w  w.  j a v  a  2 s.com*/
     * Load the lines from a local text file into a list of strings.
     * 
     * @param file path of the file whose line must be loaded
     * @return the list of lines
     */
    public static List<String> loadLines(String file) {
        ArrayList<String> rows = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = reader.readLine()) != null) {
                rows.add(line);
            }
        } catch (IOException e) {
            System.err.println("Detected and error while reading file: " + file);
            return null;
        }
        return rows;
    }
}

Related

  1. loadKey(String filename)
  2. loadLastExpInfo(String lastExpFileName)
  3. loadLine(InputStream load)
  4. loadLineByLineAndTrim(String file_path)
  5. loadLines(InputStream in, List lines)
  6. loadLines(String fileName)
  7. loadList(File f, String enc)
  8. loadList(final File file)
  9. loadList(String listName)