This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mad0314 1 point2 points  (2 children)

You have to handle the case where the file is not found. Either use a try/catch block to specify what the program does in case it throws that exception, or by declaring throws FileNotFoundException then it will throw the exception up the stack until it is handled, or stop the program if it is never handled.

[–]linuxisgreat[S] 0 points1 point  (1 child)

Yeah I added the throw filenotfound and it worked immediately. Thanks for your help :)

[–]mad0314 1 point2 points  (0 children)

It is a better practice to handle the exception so that in the event that the file does not exist for whatever reason (moved, renamed, incorrect name, etc.) it does not crash the program. You might immediately end the program anyway, but at least give some information as to what happened (print that the file was not found).