-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareTwoFiles.java
More file actions
40 lines (38 loc) · 1.58 KB
/
Copy pathCompareTwoFiles.java
File metadata and controls
40 lines (38 loc) · 1.58 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
import javax.naming.Context;
import java.io.*;
import java.util.*;
public class CompareTwoFiles {
public static void main(String[] args) throws IOException {
String first = "", second = "";
String firstName = "", secondName = "";
Scanner input = new Scanner(System.in);
System.out.print("Enter a first file name: ");
firstName = input.nextLine();
System.out.print("Enter a second file name: ");
secondName = input.nextLine();
Scanner input1 = new Scanner(new File(firstName));
Scanner input2 = new Scanner(new File(secondName));
File dir1 = new File("Different1.csv");
if (!dir1.exists()) {
while (input1.hasNextLine() && input2.hasNextLine()) {
first = input1.nextLine();
second = input2.nextLine();
if (!first.equals(second)) {
System.out.println("Differences found: " + "\n" + first + '\n' + second);
PrintWriter writer;
writer = new PrintWriter(new FileWriter(dir1, true));
String dif = new String(first);
String dif2 = new String(second);
StringBuffer sb = new StringBuffer();
sb.append(dif + ";" + dif2);
writer.println(sb);
writer.flush();
writer.close();
}
}
} else {
System.out.println("File Different1.csv exists");
}
System.out.println("done!");
}
}