[英]Java class.getResourceAsStream does not work for files with leading dot
Running this Maven project from Eclipse this does not work: 从Eclipse运行此Maven项目不起作用:
MyClass.class.getResourceAsStream("/package/to/my/resource/" + ".gitignore");
But when I rename the .gitignore
to gitignore
this works pretty fine: 但是,当我将.gitignore
重命名为gitignore
这工作得很好:
MyClass.class.getResourceAsStream("/package/to/my/resource/" + "gitignore");
The resource files are located under src/main/resources/package/to/my/resource/
. 资源文件位于src/main/resources/package/to/my/resource/
。 The maven-resources-plugin
is not configured in the pom.xml. 没有在pom.xml中配置maven-resources-plugin
。
The .* files are not moved to target/classes. 。*文件不会移至目标/类。
Java shouldn't have any problem with "hidden" files. Java的“隐藏”文件应该没有任何问题。 You need to check the output/target folder after building the project. 构建项目后,您需要检查output / target文件夹。 You should find there a /package/to/my/resource/.gitignore
file. 您应该找到一个/package/to/my/resource/.gitignore
文件。 If you cannot find it you should double check Java Build Path in project properties if there is no exclusion for files which begin with a dot. 如果找不到,则应在项目属性中再次检查“ Java构建路径”,如果不排除以点开头的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.