java - IntelliJ Idea - 通过 IntelliJ 运行时找不到输入文件(bank.in)
问题描述
我有一个作业,我是在 Linux、Visual Studio Code 和命令行上完成的。在我需要调试我的代码之前,它工作得非常好。所以我迁移到了 Windows 10,因为我在那里安装了 IntelliJ IDEA。我编译了代码并将输入文件“bank.in”放在与编译的“MyClass.class”相同的文件夹中
但是,当我从 IntelliJ 运行程序时,我的代码捕获了一个异常,即当它与“MyClass.class”位于同一文件夹中时,它无法找到文件“bank.in”。
我创建 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 运行它时,它工作正常。有什么解决方法吗?谢谢你。
解决方案
推荐阅读
- c# - 如何从外部结构的对象访问嵌套结构的属性
- amazon-web-services - AWS HTTP Gateway:相同路由的多种方法,不包括使用无服务器框架的选项
- laravel - Laravel 自定义邮箱验证
- r - R计算日期差异时的函数错误
- c++ - Boost Python - 对`_Py_NoneStruct'的未定义引用
- python - txt 中的数据格式。文件
- javascript - Javascript:什么是 Http 服务中的 reportProgress?
- testng - TestNG-每次运行后都会覆盖结果
- javascript - WebAudio 音频上下文内存泄漏
- node.js - 使用nodejs进行http post请求时出错