- 项目文件
- 配置文件夹
- 特定文件.props
- 配置文件夹
这是我的属性所在的位置,但仍然找不到路径..
我试过了
input = MainClass.class.getResourceAsStream("/config/specificfiles.props");
if(input==null){
System.out.println("Sorry, unable to find ");
return;
}
还有这个
String filename = "specificfiles.props";
input = MainClass.class.getClassLoader().getResourceAsStream(filename);
if(input==null){
System.out.println("Sorry, unable to find " + filename);
return;
}
我也尝试过这些东西没有工作。
特定文件.props
/specificfiles.props
config/specificfiles.props
项目名称/config/specificfiles.props
我尝试在这里搜索其他问题,但没有解决我的问题.. 请帮忙!
最佳答案
资源和文件完全不同,不要混淆。
资源是在类路径中搜索的,因此它们通常不放在项目的根文件夹中,而是放在源代码旁边。或者在 Maven 项目中进入 src/main/resources
。
关于java - java中找不到路径名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43109270/