-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileComparison.java
More file actions
37 lines (29 loc) · 1.23 KB
/
FileComparison.java
File metadata and controls
37 lines (29 loc) · 1.23 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
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class FileComparison {
public static void main(String[] args) throws IOException {
Scanner inputScanner = new Scanner(System.in);
System.out.print("Enter a file to compress and decompress: ");
String fileName = inputScanner.nextLine();
File inFile = new File(fileName);
Compressor compressor = new Compressor(Main.getFileString(fileName));
Decompressor decompressor = new Decompressor(compressor.compress());
Scanner file1Scanner = new Scanner(inFile);
Scanner file2Scanner = new Scanner(decompressor.decompress());
file1Scanner.useDelimiter("");
file2Scanner.useDelimiter("");
int totalChars = 0;
int totalMessUps = 0;
while (file1Scanner.hasNext() && file2Scanner.hasNext()) {
char c1 = file1Scanner.next().charAt(0);
char c2 = file2Scanner.next().charAt(0);
totalChars++;
if (c1 != c2) {
totalMessUps++;
}
}
int totalRestored = totalChars - totalMessUps;
System.out.printf("%.2f%% of the file was restored", 100 * ((double) totalRestored) / totalChars);
}
}