java.io.FileNotFoundException :(没有这样的文件或目录)从eclipse运行时 [英] java.io.FileNotFoundException: (No such file or directory) when running from eclipse

查看:565
本文介绍了java.io.FileNotFoundException :(没有这样的文件或目录)从eclipse运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个文件并想要控制台输出,

I am writing to a file and want console output,

// 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);
}

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

This gives me console output, but it throws the following exception:

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)

该文件确实存在。

推荐答案

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

The file should be in contained within the root of your project.

在eclipse中执行项目时,工作目录是项目的最高级别。

When you execute a project in eclipse, the working directory is the most top level of your project.

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

Right click your project, click New>File, and make a txt file called "TheGame.txt".

这篇关于java.io.FileNotFoundException :(没有这样的文件或目录)从eclipse运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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