URL propFile = this.getClass().getResource("/sample.xml");
我正在使用上述方法加载属性文件。并尝试在Web应用程序项目中对其进行操作。我的sample.xml存在于我的war文件src.main.resources文件夹中。
public void saveProperties(Properties prop) {
log.info("URL is ::::::::::::::::::::" + propFile);
FileSystem fs = FileSystems.getDefault();
Path workflowPath = fs.getPath(propFile.getPath());
try {
OutputStream os = Files.newOutputStream(workflowPath);
prop.storeToXML(os, "modified the path");
} catch (IOException e) {
e.printStackTrace();
}
}
public Properties getAllProperties() {
Properties pro = new Properties();
try {
pro.loadFromXML(propFile.openStream());
} catch (IOException e) {
e.printStackTrace();
}
return pro;
}
我有两种方法。不确定为什么saveProperties
抛出FileNotFoundException
和getAllProperties
正在加载同一文件中的所有属性。
异常堆栈跟踪
17:40:43,288 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) java.nio.file.NoSuchFileException: /content/bwFLA.ear/workflows.war/WEB-INF/classes/sample.xml
17:40:43,288 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
17:40:43,289 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
17:40:43,289 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
17:40:43,290 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
17:40:43,290 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:430)
17:40:43,290 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at java.nio.file.Files.newOutputStream(Files.java:170)
17:40:43,291 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at de.bwl.bwfla.workflows.beans.common.PropertiesUtil.saveProperties(PropertiesUtil.java:35)
17:40:43,291 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at de.bwl.bwfla.workflows.beans.conf.WF_CONF_0.navigate(WF_CONF_0.java:44)
17:40:43,291 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at de.bwl.bwfla.workflows.beans.conf.WF_CONF_0$Proxy$_$$_WeldClientProxy.navigate(WF_CONF_0$Proxy$_$$_WeldClientProxy.java)
17:40:43,292 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:40:43,292 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
17:40:43,293 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17:40:43,293 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at java.lang.reflect.Method.invoke(Method.java:606)
17:40:43,294 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
17:40:43,294 ERROR [stderr] (http-localhost-127.0.0.1-8080-5) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278