Close a Scanner linked to System.in

后端 未结 5 1386
抹茶落季
抹茶落季 2020-11-22 02:57

I have a Scanner linked to System.in. Now, after using the Scanner, I should close it, as it is bad coding practice to leave it open.

5条回答
  •  太阳男子
    2020-11-22 03:24

    The simplest thing is to not close Scanner if you don't want to close the underlying stream.

    Ideally you should create just one Scanner which you use for the life of the program. In any case, it appears you don't have a good reason to close it.

提交回复
热议问题