0
I want to know what the function of try
Example: try (Scanner keyboard = new Scanner (System.in)) { Some of my code didnt use 'try' . Can i know why?
1 Answer
+ 4
Learn about Exception handling in Java... ( try {.. } catch() {.. } blocks...
Your example is having try with resources concept which is closed files automatically after that block, which you opened in try argument...
You can use those, if you need them..
edit:
https://www.geeksforgeeks.org/try-with-resources-feature-in-java/amp/
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html