import java.io.*; import java.nio.file.*; public class NIOStreamRead { public static void main(String args[]) { int i; // Open the file and obtain an stream linked to it try(InputStream fin = Files.newInputStream(Paths.get("NIOStreamRead/test.txt"))) { do { i = fin.read(); if(i != -1) System.out.print((char) i); } while(i != -1); } catch(InvalidPathException e) { System.out.println("Path Error " + e); } catch(IOException e) { System.out.println("I/O Error " + e); } } }