Java Path File Read nio readFileByLines(String filePath)

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

Description

read File By Lines

License

Apache License

Declaration

public static List<String> readFileByLines(String filePath) 

Method Source Code


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

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class Main {

    public static List<String> readFileByLines(String filePath) {
        Path path = new File(filePath).toPath();
        return readFileByLines(path);
    }//ww  w. j  ava 2  s . c o m

    public static List<String> readFileByLines(File file) {
        return readFileByLines(file.toPath());
    }

    private static List<String> readFileByLines(Path path) {
        List<String> lines = null;
        try {
            lines = Files.readAllLines(path, Charset.defaultCharset());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lines;
    }
}

Related

  1. readFile(String path)
  2. readFile(String path)
  3. readFile(String path)
  4. readFileAsString(String filePath)
  5. readFileAsString(String path)
  6. readFileIntoString(Path path)
  7. readFileLines(Path file)
  8. readFileRows(Path path)
  9. readFileToSingleString(String path)