Using the newInputStream() Method to read the content of a file - Java File Path IO

Java examples for File Path IO:File Operation

Description

Using the newInputStream() Method to read the content of a file

Demo Code

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("C:/folder1/equipment", "test.txt");

    int n;//  w  ww  .j av a2  s .  com
    try (InputStream in = Files.newInputStream(path)) {
      while ((n = in.read()) != -1) {
        System.out.print((char) n);
      }
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials