关闭system.in后的NoSuchElementException [英] NoSuchElementException after closing system.in

查看:149
本文介绍了关闭system.in后的NoSuchElementException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[中断线程等待用户输入然后退出应用程序]

我想进行与上述链接中提到的相同的练习。但是,当我成功关闭<$ c $后,当我尝试使用 inConsole.nextLine()时,我遇到了 NoSuchElementException c> BufferedReader对象,尽管重新分配 inConsole ,如 inConsole = new Scanner(System.in)从标准输入读取。

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.

关闭 BufferedReader对象后,我不能像上面那样重新分配给Scanner对象并使用它吗?

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

推荐答案

永远不要关闭 System.in 系统。出。这将起作用并导致一些奇怪的效果。实际上你永远无法分别读取或写入SYSOUT的SYSIN。找其他解决方案。

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.

如果您需要建议如何在不关闭 System.in 的情况下解决问题,请提供有关您生命周期的更多信息应用程序,可能会发送相关的代码片段。

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.

这篇关于关闭system.in后的NoSuchElementException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆