Java Path File Read nio readLineByLine(String filePath)

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

Description

read Line By Line

License

Open Source License

Declaration

private static String readLineByLine(String filePath) 

Method Source Code


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

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import java.util.stream.Stream;

public class Main {
    private static String readLineByLine(String filePath) {
        StringBuilder contentBuilder = new StringBuilder();
        try (Stream<String> stream = Files.lines(Paths.get(filePath), StandardCharsets.UTF_8)) {
            stream.forEach(s -> contentBuilder.append(s).append("\n"));
        } catch (IOException e) {
            e.printStackTrace();/* w  w w.  j a v a 2  s . c o m*/
        }
        return contentBuilder.toString();
    }
}

Related

  1. readIntsFromFile(String filePath)
  2. readJson(Class dataClass, Path path)
  3. readJsonObject(Path path, TypeReference typeReference)
  4. readKeyFile(String path)
  5. readLine(BufferedReader br, Path path)
  6. readLines(Path path, boolean ignoreComments)
  7. readLineS(String filePath, int line)
  8. readLinesFromFile(Path path)
  9. readLinesFromFileLazy(String path)