-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion59.java
More file actions
34 lines (32 loc) · 781 Bytes
/
Question59.java
File metadata and controls
34 lines (32 loc) · 781 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
26
27
28
29
30
31
32
33
34
import java.io.*;
/* a program to use Byte stream class to read from a text file
and copy the content to another text file */
class Question59 {
public static void main(String[] args) {
FileInputStream fin = null;
FileOutputStream fout = null;
try {
fin = new FileInputStream ("File/Test3.txt");
fout = new FileOutputStream ("File/Test3_target.txt");
int k;
String msg = " Target file!";
while ((k = fin.read ()) != -1) {
System.out.print ((char) k);
fout.write (k);
}
fout.write (msg.getBytes ());
}
catch (IOException ioe) {
System.out.println ("I/O Exception!\n" + ioe);
}
finally {
try {
fin.close ();
fout.close ();
}
catch (IOException ioe) {
System.out.println ("I/O Exception!\n" + ioe);
}
}
}
}