通过JNLP写入本地文件 [英] Write to a local file through JNLP
问题描述
我有一个特定的要求,从jar文件中读取资源,然后将其写入本地磁盘。但是当我尝试将该资源写入本地磁盘时出现异常:
引发java.io.FilePermission(write)。
我的罐子已签名。我也尝试过以下解决方案,但它也不起作用。
AccessController.doPrivileged(new PrivilegedAction()
似乎没什么用。
我错过了一步签署jar后,因为这是最常见的解决方案吗?
如何在不使用策略文件的情况下写入本地文件(因为不能在每个文件上执行客户机)?
JNLP还需要指定:
< security>
< all-permissions />
< / security>
参见 JNLP文件语法了解详情。
我通常会使用 FileSaveService
详见汤姆的回答,但这听起来更像是一个t的情况他'''可以是用于配置应用程序的默认属性文件。自应用程序以来,保存服务不太适合。无法知道文件的存储位置或以后如何访问它。出于安全原因,代替文件
提供的 FileContents
对象没有返回路径的方法。 / p>
在这种情况下,提取配置的详细信息。文件&使用JNLP API的 PersistenceService
存储它们。这是一个演示。 PersistenceService
。此服务也适用于沙盒应用。 (没有代码签署伏都教)。
I have a specific requirement to read a resource from jar file and then write it to local disk. But when I try to write that resource to local disk an exception:
java.io.FilePermission (write) is raised.
I have my jar signed. I have also tried the following solution but it does not work either.
AccessController.doPrivileged(new PrivilegedAction()
Nothing seems to work.
Am I missing a step after signing jar because this is the most common solution available everywhere?
How can I write to a local file without using policy files (because that can't be done on each client machine)?
The JNLP also needs to specify:
<security>
<all-permissions/>
</security>
See the JNLP File Syntax for details.
I would generally use the FileSaveService
as detailed in Tom's answer, but this sounds more like a situation where the 'file' could be a default properties file for configuring the app. The save service is not well suited to that, since the app. has no way to know where the file is stored, or how to access it later. For security reasons, the FileContents
object that is provided in place of a File
has no methods that return the path.
In that case, extract the details of the config. file & store them using the PersistenceService
of the JNLP API. Here is a demo. of the PersistenceService
. This service is also available to sand-boxed apps. (no code signing voodoo).
这篇关于通过JNLP写入本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!