Java Path File Read nio readFileToSingleString(String path)

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

Description

Get the content of a text file as a single string.

License

LGPL

Declaration

public static String readFileToSingleString(String path) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;
import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*from  w w w.j  av a  2s.  c  om*/
     * Get the content of a text file as a single string.
     */
    public static String readFileToSingleString(String path) throws IOException {
        List<String> lns = new ArrayList<>();
        try {
            lns = Files.readAllLines(new File(path).toPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        StringBuilder sb = new StringBuilder();
        for (String x : lns)
            sb.append(x).append("\n");
        return sb.toString();
    }
}

Related

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