Skip to content
Advertisement

Access variable in try block

I want to remove the throws FileNotFoundException from the method head and put it into it.

JavaScript

But then I can’t access in (the scanner) anymore! How to handle that?

JavaScript

Advertisement

Answer

The variable in is out of scope outside the try block. You can either do this:

JavaScript

Or better yet, try with resources

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement