forked from Labore/PR2-L
1
0
Fork 0
PR2-L/NIOStreamRead/src/NIOStreamRead.java

29 lines
533 B
Java

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);
}
}
}