Java Path File Read nio read(String aPathString)

Here you can find the source of read(String aPathString)

Description

read

License

Open Source License

Declaration

public static String read(String aPathString) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    public static String read(String aPathString) throws IOException {
        StringBuilder sb = new StringBuilder();
        Path path = Paths.get(aPathString);
        try (BufferedReader reader = Files.newBufferedReader(path, Charset.defaultCharset())) {
            String line = reader.readLine();
            while (line != null) {
                sb.append(line);//from   w w  w .  j a  v  a2  s  .  c  om
                sb.append(System.lineSeparator());
                line = reader.readLine();
            }

        }
        return sb.toString();
    }
}

Related

  1. newBufferedReader(Path path)
  2. newBufferedReader(Path path)
  3. openBufferedReader(String pathOrUrl)
  4. openForReadingAndWriting(String filePath)
  5. openResourceReader(Class resourceOrigin, String resourcePath)
  6. read(String filePath)
  7. read(String filePath)
  8. read(String path)
  9. readAllLines(Path path)