System.in, Scanner, and File Descriptors – JAVA Case study
dev.to·7h·
Discuss: DEV
Flag this post

Hello, Everyone, I am currently learning Java. As a beginner, I worked with console IO. To read input from the terminal, I use the Scanner class.

I tried a mini CLI project, so I used the Scanner object in different classes. For resource management, the Scanner object — especially when reading from sources like System.in or files — utilizes underlying system resources (like file descriptors or input streams). Closing the Scanner explicitly releases these resources back to the operating system, preventing resource leaks.

So, I closed the Scanner in each class, but after running my program, I got this exception:

Exception in thread "main" java.util.NoSuchElementException

This was the first time I saw this exception. After reading some related S…

Similar Posts

Loading similar posts...