Java Files.newInputStream(Path path, OpenOption ... options)
Syntax
Files.newInputStream(Path path, OpenOption ... options) has the following syntax.
public static InputStream newInputStream(Path path, OpenOption ... options) throws IOException
Example
In the following code shows how to use Files.newInputStream(Path path, OpenOption ... options) method.
/*from w w w . j a va 2 s . c o m*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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 rn_demo = Paths.get("C:/tutorial/Java", "demo.txt");
//using NIO.2 unbuffered stream
int n;
try (InputStream in = Files.newInputStream(rn_demo)) {
while ((n = in.read()) != -1) {
System.out.print((char) n);
}
} catch (IOException e) {
System.err.println(e);
}
}
}