更新捆绑的资源文件 [英] Updating a bundled resource file

查看:91
本文介绍了更新捆绑的资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做以下事情,

String str = "this is the new string";
URL resourceUrl = getClass().getResource("path_to_resource");
File file = new File(resourceUrl.toURI());
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(xml);
writer.close();

在上面的代码中,我试图写入我的一个java包中包含的资源文件。执行代码后,我的程序执行正常,但文件只更新web-INF中的属性文件,而不是存储它的包。任何人都可以帮我解释如何实现这一点或我在这里做错了什么?非常感谢。

In the above code I am trying to write to a resource file contained in one of my java packages. After executing the code, my program executes fine but the file just updates the properties file in web-INF and not into the package where it is stored. Can anyone please help me figure how can I achieve that or what am I doing wrong here? Thanks a lot.

推荐答案

您不应该尝试写入与您的应用程序类一起存储的文件。根据应用程序服务器的不同,您尝试写入的位置可能无法写入,或者应用程序可能正在从应用程序存档(.war文件)运行。

You should not be trying to write to a file stored with your application classes. Depending on the application server, the location you are trying to write to may not be writable or the application may be running from an application archive (a .war file).

您应该使用外部文件夹来存储配置和其他应用程序数据。通常,您通过环境变量或部署期间指定的属性指定此文件夹。

You should use an external folder to store configuration and other application data. Typically, you specify this folder via an environment variable or a property specified during deployment.

这篇关于更新捆绑的资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆