Java Path File Read nio readTextFromFile(String textFilePath)

Here you can find the source of readTextFromFile(String textFilePath)

Description

read Text From File

License

Open Source License

Declaration

public static String[] readTextFromFile(String textFilePath) 

Method Source Code

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

import java.io.IOException;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import java.util.List;

public class Main {
    public static String[] readTextFromFile(String textFilePath) {
        String[] linesArr = null;
        Path filePath = Paths.get(textFilePath);
        Charset charset = Charset.forName("ISO-8859-1");
        try {/*w  w  w.  j  a va 2s.c  o  m*/
            List<String> lines = Files.readAllLines(filePath, charset);
            linesArr = new String[lines.size()];
            for (int i = 0; i < lines.size(); i++) {
                linesArr[i] = lines.get(i);
            }
        } catch (IOException e) {
            System.out.println(e);
        }
        return linesArr;
    }
}

Related

  1. readPropertiesFile(Path path)
  2. readSheBang(Path script)
  3. readStringFromPath(Path path)
  4. readTextFile(Path p)
  5. readTextFileFromResources(String filepath, ClassLoader classLoader)
  6. setReadable(final Path path, boolean readable)
  7. setReadOnly(Path file)