Hello everyone,
So I was presented a job by someone to make an application that would list duplicate files in the current working directory.
Eventually it will give you a choice on what you can do with the duplicate files, but, for now it is going to just list them.
I am using Java (by choice), and I wrote out about 50 lines of code for this. It took me about 20 minutes, and I ran a test inside of eclipse and I got the InputMismatchException. However I get it right when the application goes to run. So I went ahead and compiled the project to test it in Command Prompt, and right when I run it (using java -jar Duplicates.jar) it says:
No Main Manifest Attribute, in Duplicates.jar
Now I think that was something that went wrong when I compiled, I just want to figure out why or how I am getting an InputMismatchException. It says it is occurring at lines 17 and 46. Below is my code, I have comments on lines 17 and 46.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class DuplicateFileRemover {
public static boolean CompareFiles(File x, File y) {
try {
Scanner xs = new Scanner(x);
Scanner ys = new Scanner(y);
boolean result = true;
while (result == true) {
if (xs.nextByte() != ys.nextByte()) {
result = false;
}
return result;
}
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
return false;
}
public static void main(String[] args) {
File dir = new File(".");
File[] fileList = dir.listFiles();
for (int x = 0; x < fileList.length; x++) {
for (int y = x+1; y < fileList.length; y++) {
if (CompareFiles(fileList[x], fileList[y])) {
System.out.println(fileList[x]);
}
}
}
}
}
Can anyone see a problem with my code? Since I am dealing with files I knew I probably needed to catch a possible FileNotFound exception.
Again, like I said before, there is no user input required, the application runs solely on getting files in the current working directory.
Please help.