So I have the following code:
import java.io.*;
public class Plagiarism {
public static void main(String[] args) {
Plagiarism myPlag = new Plagiarism();
if (args.length == 0) {
System.out.println("Error: No files input");
}
else if (args.length > 0) {
try {
for (int i = 0; i < args.length; i++) {
BufferedReader reader = new BufferedReader (new FileReader (args[i]));
simplify (reader);
reader.close();
}
}
catch (Exception e) {
System.err.println ("Error reading from file");
}
}
}
public static void simplify(BufferedReader input) throws IOException {
String line = null;
line = input.readLine();
while (line != null) {
line = line.replaceAll ("[^a-zA-Z0-9 ]", "");
line = line.toLowerCase();
}
}
}
The problem with this code is that it compiles, but when i run it and add in the 2 arguments in command line eg. Java Plagiarism text1.txt text2.txt. EDIT: When I run this it just doesn't do anything or even finish, it's like it's stuck somewhere.
Thanks for any help.
System.out.println(e.getMessage());in yourcatchclause to learn what the exception is.Exceptionbut a more specific one.Exceptionalso catchesRuntimeExceptionand derivates, therefore all unchecked exceptions.