所以我遇到了 Lanterna,我决定将它用于我的基于终端的文本编辑器项目,但是当您尝试在 Windows 上运行基本的创建终端样板代码时,您将收到 IOException 错误。
这是代码:
public class Main {
public static void main(String[] args) {
Terminal terminal = new DefaultTerminalFactory().createTerminal();
}
}
这是错误:
java: unreported exception java.io.IOException; must be caught or declared to be thrown
解决方案很简单,只需导入 IOException 并将终端样板代码包含在 try catch 表达式中即可。
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try{
Terminal terminal = new DefaultTerminalFactory().createTerminal();
}
catch(IOException e){
e.printStackTrace();
}
}
}
现在代码将运行,没有任何错误