- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteIO.java
More file actions
Latest commit
25 lines (22 loc) · 811 Bytes
/
Copy pathByteIO.java
File metadata and controls
25 lines (22 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// File I/O using standard byte streams (Oracle Java Tutorials)
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
classByteIO {
publicstaticvoidmain(String[] args) {
// NOTE: all byte stream classes are derived from InputStream
// or OutStream
intc;
// this requires xanadu.txt to be found here:
// https://docs.oracle.com/javase/tutorial/essential/io/streams.html
try(FileInputStreaminFile = newFileInputStream("xanadu.txt");
FileOutputStreamoutFile = newFileOutputStream("outfile.txt");) {
// read file byte by byte and write to another file
while ((c = inFile.read()) != -1)
outFile.write(c);
} catch (IOExceptionaExc) {
System.out.println("An exception has occurred: " + aExc);
aExc.printStackTrace();
}
}
}