我正在编写一个应用程序,该应用程序将在JBoss EAP 6.3.1中运行在CentOS 6.5 上
在这个应用程序中,我必须将一个文件保存到磁盘上,当重新启动应用程序时,我必须把它读回应用程序中。
所有这些都在起作用。
问题是我想保存到应用程序工作目录中的文件中。
现在发生的事情是,文件:foo.bar将保存在我运行standalone.sh(或Windows上的.bat)的位置。
public void saveToFile() throws IOException {
String foo = "bar";
Writer out = new OutputStreamWriter(new FileOutputStream("/foo.bar"), "UTF-8");
try {
out.write(foo);
} finally {
out.close();
}
}
您可以尝试使用一个绝对路径来保存您的文件:
String yourSystemPath = System.getProperty("jboss.home.url") /*OPTIONAL*/ + "/want/to/save/here";
File fileToSave = new File(yourSystemPath,"foo.bar");
Writer out = new OutputStreamWriter(new FileOutputStream(fileToSave), "UTF-8");
基本上,在这里,我使用yourSystemPath
变量创建一个File
对象,我在其中存储了保存文件的路径,然后使用之前创建的对象File
创建new FileOutputStream(fileToSave)
请确保您的JBoss服务器具有yourSystemPath
的写入权限