Skip to content
Advertisement

Tag: scoping

Access variable in try block

I want to remove the throws FileNotFoundException from the method head and put it into it. But then I can’t access in (the scanner) anymore! How to handle that? Answer The variable in is out of scope outside the try block. You can either do this: Or better yet, try with resources

Advertisement