[英]getClassLoader().getResourceAsStream method returns null for a file with “.LIB” extension
I'm trying to load a file from resources/ path using 我正在尝试使用资源/路径加载文件
getClassLoader().getResourceAsStream("file.LIB")
but the method always returns null, unless I rename the file into another extension, say ".dll". 但该方法始终返回null,除非我将文件重命名为另一个扩展名,例如“.dll”。
I've looked into the official Java documentation, but to no avail. 我查看了官方的Java文档,但无济于事。
Why does the method acts strange on that file type? 为什么该方法对该文件类型的行为很奇怪?
Note: I'm using JDK 1.8.0_111 x86 (due to constraints on that lib file, which only works well with a 32-bit JVM) 注意:我使用的是JDK 1.8.0_111 x86(由于该lib文件的限制,只适用于32位JVM)
It does works for me, you need to be sure what exactly you are doing with lib file. 它确实适用于我,你需要确定你正在使用lib文件做什么。
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class FileHelper {
public String getFilePathToSave() {
Properties prop = new Properties();
String filePath = "";
try {
InputStream inputStream =
getClass().getClassLoader().getResourceAsStream("abc.lib");
prop.load(inputStream);
filePath = prop.getProperty("json.filepath");
} catch (IOException e) {
e.printStackTrace();
}
return filePath;
}
public static void main(String args[]) {
FileHelper fh = new FileHelper();
System.out.println(fh.getFilePathToSave());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.