【发布时间】:2020-11-11 06:03:47
【问题描述】:
在我的独立应用程序中,我必须从不同类的控制台读取用户输入。 我在 Installer 类中创建了一个静态类成员变量
public static final BufferedReader buffReader = new BufferedReader(new InputStreamReader(System.in));
但是 Installer.buffReader.readLine();抛出 IO 异常 - “暂时不可用的资源” 有时
public static void startApplication() {
System.out.println("Would you like to start the application? [y/n]");
String userChoice = null;
try {
userChoice = Installer.buffReader.readLine();
if (userChoice != null && userChoice.equalsIgnoreCase("y")) {
start();
}
} catch (IOException ex) {
LOGGER.error("Exception occured in startApplication() :{}", ex.getMessage());
}
}
如何调试或防止它?
【问题讨论】:
-
问题不在
new InputStreamReader(...),而在readLine()。
标签: java io bufferedreader inputstreamreader system.in