intellij-idea 系统找不到指定的文件,

gle*_*hen 2 java eclipse intellij-idea

有人能帮我吗?我对编程还很陌生,我决定尝试从 eclipse 来的 IDEA,但我遇到了一个问题,我从 eclipse 导入了一个可以工作的项目,但在 IDEA 中,我无法像在 eclipse 中那样引用我的 res 文件夹,就像我一样不能使用 res/image.png 我只能做 c:\ect。有谁知道为什么?我已将 res 文件夹设置为资源根目录。

Ash*_*win 5

对于这样的项目结构:

project
|
| -> src
|    |
|    | -> directory
|    |    |
|    |    | -> MyClass.java
|    |    |
|    |    | -> file.txt
Run Code Online (Sandbox Code Playgroud)

使用以下代码读取 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();

        }

    }

}
Run Code Online (Sandbox Code Playgroud)