forked from Labore/PR2-L
30 lines
741 B
Java
30 lines
741 B
Java
/**Copyright (c) Schildt, H.: "Java. The Complete Reference"
|
|
* McGraw-Hill Education, Ninth Edition, 2014
|
|
* Demonstrate NIO-based, stream output. Requires JDK 7 or later., p. 711
|
|
*/
|
|
|
|
import java.io.*;
|
|
import java.nio.file.*;
|
|
|
|
public class NIOStreamWrite {
|
|
public static void main(String args[])
|
|
{
|
|
// Open the file and obtain a stream linked to it.
|
|
try(OutputStream fout = new BufferedOutputStream(
|
|
Files.newOutputStream(Paths.get("NIOStreamWrite/test.txt"))))
|
|
{
|
|
// Write some bytes to the stream
|
|
for(int i = 0; i <26; i++)
|
|
fout.write((byte)('A' + i));
|
|
}
|
|
catch(InvalidPathException e)
|
|
{
|
|
System.out.println("Path Error " + e);
|
|
}
|
|
catch(IOException e)
|
|
{
|
|
System.out.println("I/O Error " + e);
|
|
}
|
|
}
|
|
}
|