简体   繁体   English

Java读取文件权限

[英]Java Read File Permissions

I was wondering if anybody can show me way to be able to create read file permissions for my java applet. 我想知道是否有人可以告诉我能够为我的Java小程序创建读取文件权限。

The exact exception I receive is 我收到的确切例外是

java.security.AccessControlException: access denied(java.io.FilePermission filename.pdf write)

I've put f.setReadable and f.setWriteable where f is the file and nothing. 我把f.setReadablef.setWriteable放在f是文件而没有。 A little help please. 请帮助一下。

There's security limits on what an unsigned applet can do, and one of the things it can't do is access the local filesystem (see here for a full list). 对于未签名的applet可以执行的操作存在安全限制,其中一项不能访问本地文件系统的内容(请参阅此处获取完整列表)。 You have several options: 你有几个选择:

  1. Sign your applet . 签署你的小程序 If a user then runs your applet it won't run with any security restrictions. 如果用户然后运行您的applet,它将不会运行任何安全限制。 However, signing your applet with a trusted certificate costs at least $100 a year, and if you self-sign then nobody is going to trust your applet. 但是,使用受信任的证书签署您的applet每年至少花费100美元,如果您自签名,那么没有人会信任您的applet。 And even if you do sign with a trusted certificate the user might decide not to run it. 即使您使用受信任的证书进行签名,用户也可能决定不运行它。
  2. Set up your applet with a JNLP file . 使用JNLP文件设置applet。 This will let your applet use the javax.jnlp package. 这将让你的applet使用javax.jnlp包。 You can then use the FileOpenService and FileSaveService to ask the user to let you read/write one particular file. 然后,您可以使用FileOpenServiceFileSaveService要求用户允许您读/写一个特定文件。 Alternatively, you can use the PersistenceService to store a small amount of data persistently within the browser. 或者,您可以使用PersistenceService在浏览器中PersistenceService存储少量数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM