Java Path File Read nio readStringFromPath(Path path)

Here you can find the source of readStringFromPath(Path path)

Description

read String From Path

License

Apache License

Declaration

public static String readStringFromPath(Path path) throws Exception 

Method Source Code


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

import java.io.BufferedReader;
import java.io.FileReader;

import java.nio.file.Path;

public class Main {
    public static String readStringFromPath(Path path) throws Exception {
        FileReader fr = new FileReader(path.toString());
        BufferedReader br = new BufferedReader(fr);
        String content;/*from w  w w . j  av  a 2 s  .  c o m*/
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();
            while (line != null) {
                sb.append(line);
                sb.append('\n');
                line = br.readLine();
            }
            content = sb.toString();
        } finally {
            br.close();
        }
        return content;
    }
}

Related

  1. readLineSP(String filePath, int line, int pos)
  2. readLinesToString(Path file)
  3. readManifest(Path path)
  4. readPropertiesFile(Path path)
  5. readSheBang(Path script)
  6. readTextFile(Path p)
  7. readTextFileFromResources(String filepath, ClassLoader classLoader)
  8. readTextFromFile(String textFilePath)
  9. setReadable(final Path path, boolean readable)