有人可以帮助我吗?我是编程的新手,我决定尝试从 eclipse 开始使用 IDEA,但我遇到了一个问题,我从 eclipse 导入了一个项目,但在 IDEA 中,我不能像在 eclipse 中那样引用我的 res 文件夹,就像我在 eclipse 中一样不能使用 res/image.png 我只能做 c:\ect。有人知道为什么吗?我已将 res 文件夹设置为资源根目录。
最佳答案
对于这样的项目结构:
project
|
| -> src
| |
| | -> directory
| | |
| | | -> MyClass.java
| | |
| | | -> file.txt
使用下面的代码读取MyClass.java中的文件
import java.io.*;
class MyClass {
public static void main(String... args) {
try {
BufferedReader br = new BufferedReader(new FileReader("src/directory/file.txt"));
// read your file
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
关于java - intellij-idea 系统找不到指定的文件,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27982675/