NoSuchElementException after closing system.in

走远了吗. 提交于 2019-12-31 06:40:12

问题


[ Interrupt a thread waiting for user input and then exit the app ]

I wanted to do the same exercise as mentioned in the above link. But, I ran into NoSuchElementException when I tried to use inConsole.nextLine(), after successfully closing BufferedReader object, in spite of reassigning inConsole like inConsole = new Scanner(System.in) to read from Standard input.

After closing BufferedReader object, can't I reassign to Scanner object like above and use it?


回答1:


Never close neither System.in nor System.out. This will work and cause some strange effects. Actually you will never be able to read or write to SYSIN of SYSOUT respectively. Find other solution.

If you need advise how to solve your problem without closing System.in please provide more information about lifecycle of your application and probably send relevant code snippets.



来源:https://stackoverflow.com/questions/26972763/nosuchelementexception-after-closing-system-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!