java - How do I use a Scanner only once then get rid of it? -
I have a program in Java, in which I have to get user input, however, I need to get user input Once, after that, I no longer need a scanner. Do the following:
int userInput = new scanner (System.in) .nextInt (); A resource leak warns me, saying that & lt; Assigned close pricing & gt; Never goes off .
Is there another way, I can only use one scanner once and get rid of it so that there is no resource leak? There may be something similar to using the statement of C #.
Using the equivalent of using one, do not use it, It will close System.in and you do not want it. Ignore the warning for this particular case, let the garbage collector claim the scanner and leave the standard input.
Comments
Post a Comment