Java Path File Read nio readAsString(String path)

Here you can find the source of readAsString(String path)

Description

read As String

License

Apache License

Declaration

public static String readAsString(String path) throws IOException 

Method Source Code


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

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.nio.charset.StandardCharsets;

public class Main {
    public static String readAsString(String path) throws IOException {
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8))) {
            String line = null;//  w w  w.  ja  va  2 s .com
            StringBuilder sb = new StringBuilder(4096);
            while ((line = reader.readLine()) != null) {
                sb.append(line).append('\n');
            }
            return sb.toString();
        }
    }
}

Related

  1. readAllLines(Path path)
  2. readAllLines(String path)
  3. readAllLinesOrExit(Path path)
  4. readAndConsume(String filePath, Consumer consumer)
  5. readAsString(Path path)
  6. reader(String path)
  7. readers(String path)
  8. readFile(Path directory, String... parts)
  9. readFile(Path file)