gpt4 book ai didi

java.io.FileNotFoundException : (No such file or directory) when running from eclipse 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:34:34 27 4
gpt4 key购买 nike

我正在写入文件并需要控制台输出,

// TODO Create a game engine and call the runGame() method
public static void main(String[] args) throws Exception {
NewGame myGame = new TheGame().new NewGame();
myGame.runGame();
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
}

这给了我控制台输出,但抛出了以下异常:

java.io.FileNotFoundException: TheGame.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at game.main(TheGame.java:512)

文件确实存在。

最佳答案

该文件应包含在项目的根目录中。

当您在 eclipse 中执行项目时,工作目录是项目的最顶层。

右键单击您的项目,单击“新建”>"file",然后创建一个名为“TheGame.txt”的 txt 文件。

关于java.io.FileNotFoundException : (No such file or directory) when running from eclipse 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18709334/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com