【发布时间】:2022-02-06 18:48:33
【问题描述】:
我正在使用 Intellij Idea - 2021.3.2 和 Java 8。在 Intellij 中,我无法读取同一模块中另一个包中的文件。该文件位于主文件夹而不是资源文件夹下。但在 Eclipse 中,我可以阅读。
例如。下面的代码在 eclipse 和 intellij 中打印不同的输出。
import java.net.URL;
public class TestMain {
public static void main(String[] args) {
URL resource = TestMain.class.getResource("/org/files/input.txt");
if(resource == null) {
System.out.println("Resource is null");
} else {
System.out.println("Resource found!!");
}
}
}
在 Intellij 中,代码打印“Resource is null”,但在 eclipse 中,代码打印“Resource found!!”。
我需要在 intellij 中启用/禁用任何设置吗?为什么 Intellij Idea 中的代码表现不同?
【问题讨论】:
标签: intellij-idea