I'm trying to pass in a text file(input and output files) as the command line arguments inside a try-catch block.
This is a snippet of the code:
try {
PrintWriter outFile = new PrintWriter(new FileOutputStream(args[0]));
} catch (FileNotFoundException exc) {
System.out.println("file does not exist");
} catch (Exception e) {
System.out.println("general exception");
}
I'm trying to check it by passing a file that doesn't exist but it doesn't seem to work, not even in the general exception. I tried printStream as well but nothing really changed.
Any help would be appreciated, thanks!
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.Perhaps the file you are passing in CAN be created, so it is creating it for you. Maybe make the directory read only and see if it still works.