Java Path File Read nio readFileIntoString(Path path)

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

Description

read File Into String

License

Open Source License

Declaration

public static String readFileIntoString(Path path) 

Method Source Code

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

import java.io.File;
import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;

import java.util.stream.Collectors;

public class Main {
    public static String readFileIntoString(String file) {
        return readFileIntoString(new File(file));
    }/*from  ww w  .  j a  v  a 2  s . c  o m*/

    public static String readFileIntoString(File file) {
        return readFileIntoString(file.toPath());
    }

    public static String readFileIntoString(Path path) {
        try {
            return Files.lines(path).collect(Collectors.joining("\n"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

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