-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyFiles.java
More file actions
43 lines (39 loc) · 1.41 KB
/
CopyFiles.java
File metadata and controls
43 lines (39 loc) · 1.41 KB
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
35
36
37
38
39
40
41
42
43
package stream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
public class CopyFile {
public static void main(String[] args) throws IOException {
FileInputStream fileInput = new FileInputStream("C:\\MyJava\\Data.txt");
FileOutputStream fileOutput = new FileOutputStream("C:\\MyJava\\Text.txt");
int ch = 0;
while((ch=fileInput.read())!=-1) {
if (ch >= 91 && ch <= 123)
fileOutput.write(ch - 32);
else
fileOutput.write(ch);
}
fileInput.close();
fileOutput.close();
FileInputStream file1 = new FileInputStream("C:\\MyJava\\Data.txt");
FileInputStream file2 = new FileInputStream("C:\\MyJava\\Text.txt");
FileOutputStream both = new FileOutputStream("C:\\MyJava\\Both.txt");
// By using SequenceInputStream, need single loop
ch = 0;
SequenceInputStream write = new SequenceInputStream(file1, file2);
while((ch=write.read())!=-1){
both.write(ch);
}
// By using two loop
ch = 0;
/* while((ch= file1.read())!=-1) {both.write(ch);}
both.write(10); // for the next line
file1.close();
ch = 0;
while((ch= file2.read())!=-1) {
both.write(ch);
}
file2.close(); */
}
}