我的项目目录结构(在Eclipse中):
MyProject/
src/ --> "source directory" on Eclipse's classpath/buildpath
com.me.myapp
Driver
myconfig.txt
在
Driver
中,我有以下代码:public class Driver {
public static void main(String[] args) {
InputStream is = ClassLoader.getSystemClassLoader.getResourceAsStream("myconfig.txt");
if(is == null)
System.out.println("input stream is null");
else
System.out.println("input stream is NOT null :-)");
}
}
当我运行这个程序时,会在控制台输出以下内容:
input stream is null
为什么会把
myconfig.txt
放错位置了?是我错误地使用了ClassLoader API吗?还是其他原因?