Java Text File Read Line readLines(String filePath)

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

Description

read Lines

License

Apache License

Declaration

public static List<String> readLines(String filePath) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> readLines(String filePath) throws IOException {

        return readLines(filePath, "utf-8");
    }/*from w  w  w  .  j a va2  s  .c  o m*/

    public static List<String> readLines(String filePath, String encode) throws IOException {

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(new FileInputStream(new File(filePath)), encode));
        List<String> lines = new ArrayList<String>();
        String line;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (!line.equals(""))
                lines.add(line);
        }
        reader.close();
        return lines;
    }
}

Related

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