Java Files.readAllLines(Path path, Charset cs)

Syntax

Files.readAllLines(Path path, Charset cs) has the following syntax.

public static List < String > readAllLines(Path path,    Charset cs)     throws IOException

Example

In the following code shows how to use Files.readAllLines(Path path, Charset cs) method.


//from www  .j  a va  2 s .c om
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 void main(String[] args) {

    Path wiki_path = Paths.get("C:/tutorial/wiki", "wiki.txt");

    Charset charset = Charset.forName("ISO-8859-1");
    try {
      List<String> lines = Files.readAllLines(wiki_path, charset);

      for (String line : lines) {
        System.out.println(line);
      }
    } catch (IOException e) {
      System.out.println(e);
    }

  }
}




















Home »
  Java Tutorial »
    java.nio.file »




DirectoryStream.Filter
Files
FileStore
FileSystem
FileVisitor
Path
Paths
WatchService