Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
58 lines (49 loc) · 1.13 KB

File metadata and controls

58 lines (49 loc) · 1.13 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Projbect 10-1
Compare two files.
To use this program, specify the names of the files to be compared on the command line.
java CompFile FIRST.TXT SECOND.TXT
*/
import java.io.*;
class CompFiles {
public static void main(String args[]) throws IOException {
int i=0, j=0;
FileInputStream f1;
FileInputStream f2;
try {
// open first file
try {
f1 = new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println(args[0] + " File Not Found");
return;
}
// open second file
try {
f2 = new FileInputStream(args[1]);
} catch(FileNotFoundException exc) {
System.out.println(args[1] + " File Not Found");
return;
}
} catch(ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: CompFiles f1 f2");
return;
}
// Compare files
try {
do {
i = f1.read();
j = f2.read();
if(i != j) break;
} while(i != -1 && j != -1);
} catch(IOException exc) {
System.out.println("File Error");
}
if(i != j)
System.out.println("Files differ.");
else
System.out.println("Files are the same.");
f1.close();
f2.close();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.