通过 JNLP 写入本地文件 [英] Write to a local file through JNLP

查看:30
本文介绍了通过 JNLP 写入本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定的要求,从 jar 文件中读取资源,然后将其写入本地磁盘.但是当我尝试将该资源写入本地磁盘时出现异常:

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() 

似乎没有任何效果.

我是否在签署 jar 后遗漏了一步,因为这是随处可用的最常见的解决方案?

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)?

推荐答案

JNLP 还需要指定:

The JNLP also needs to specify:

<security>
    <all-permissions/>
</security>

请参阅 JNLP 文件语法 了解详情.

我通常会使用 Tom 的回答中详述的 FileSaveService,但这听起来更像是文件"可能是用于配置应用程序的默认属性文件的情况.保存服务不太适合,因为应用程序.无法知道文件存储在哪里,或者以后如何访问它.出于安全原因,代替 File 提供的 FileContents 对象没有返回路径的方法.

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.

在这种情况下,提取配置的详细信息.档案及使用 JNLP API 的 PersistenceService 存储它们.这是一个 演示.PersistenceService.此服务也可用于沙盒应用程序.(没有代码签名伏都教).

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屋!

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