我有 Java webapp,我正在尝试从 classpth 读取文件。
if (fileName == null){
fileName = Thread.currentThread().getContextClassLoader().getResource("config.properties");
}
objFile = new File(fileName.toURI());
我的类路径中有 config.properties。 WEB-INF/类。当我在本地检查时,它给出: fileName.toURI()
,它给我 file:/D:/dev/Tomcat_6_0/webapps/testApp/WEB-INF/classes/config.properties
。并且工作正常。
问题出在生产Linux服务器上,我在那里得到这个路径vfsfile:/export/home/u/bin/jboss-5.1.0.BE/server/default/deploy/testApp.war/WEB-INF/classes/config.properties
.
我遇到了以下异常。
Caused by: java.lang.IllegalArgumentException: URI scheme is not "file"
at java.io.File.<init>(File.java:366)
at com.utils.ConfigLoader.loadConfigFilePath(ConfigLoader.java:87)
处理 vfs 的解决方法是什么?
最佳答案
您不得尝试将资源从类路径转换为文件。如果它位于 WAR/JAR 中,它甚至可能不是文件。 File 类仅代表文件系统对象。
关于java - URI 方案不是 "file"。无法从类路径读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10429073/