intellij idea在运行intellij时找不到输入文件(bank.in)

a9wyjsp7  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(221)

我有一个家庭作业,我在linux、visualstudio代码和命令行上做了。在我需要调试代码之前,它一直工作得很好。所以我迁移到windows10,因为我在那里安装了intellijidea。我编译了代码,并将输入文件“bank.in”与编译的“myclass.class”放在同一个文件夹中
但是,当我从intellij运行程序时,我的代码捕捉到一个异常,即当文件“bank.in”与“myclass.class”位于同一文件夹中时,它找不到该文件。
我创建bank.in的方法是,右键单击intellij中的out文件夹并添加一个新文件,然后从中添加bank.in内容
我试过使用cmd.exe运行它 java MyClass 而且效果很好。未捕获任何异常。
但当你浏览intellij idea时,就会发现

Cannot find bank.in...

    Exiting the program...

这是我输入文件的代码部分。

public void main(String[] args)
{
    String fileName = "bank.in";

    FileReader bank = null;
    BufferedReader bankBuffered = null;

    try
    {
        bank = new FileReader(fileName);
        bankBuffered = new BufferedReader(bank);
    }
    catch(FileNotFoundException f)
    {
        System.out.printf("%s is not found.%n%n", fileName);
        System.out.printf("Exiting the program...%n");
        System.exit(0);
    }
}

这是我的项目文件夹结构

MyProject
-.idea
    -encodings.xml
    -misc.xml
    -modules.xml
    -workspace.xml
-out
    -MyClass.class
    -bank.in
-src
    -MyClass.java

当我通过cmd.exe运行它时,它工作正常。有解决办法吗?谢谢您。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题