[英]class.getClassLoader getResourceasStream returns null in jar
[英]getClassLoader().getResourceAsStream method returns null for a file with “.LIB” extension
我正在尝试使用资源/路径加载文件
getClassLoader().getResourceAsStream("file.LIB")
但该方法始终返回null,除非我将文件重命名为另一个扩展名,例如“.dll”。
我查看了官方的Java文档,但无济于事。
为什么该方法对该文件类型的行为很奇怪?
注意:我使用的是JDK 1.8.0_111 x86(由于该lib文件的限制,只适用于32位JVM)
它确实适用于我,你需要确定你正在使用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.