JAVA APPLET读本地文件权限问题及解决办法
http://quicker.javaeye.com/blog/571584
综合网络上的资料有2中方法:
1,使用数字签名。
2,修改策略文件。
这里使用的方法是修改策略文件:
首先要确定IE所使用的Jre安装在哪个目录下。但没有找到比较好的方法,一般默认是C:/Program Files/Java/下。从IE的Internet选项中可以看到目前使用的版本,那就进入C:/Program Files/Java/中对应版本的文件夹。本机是C:/Program Files/Java/j2re1.4.2_05/
然后,进入到./lib/security下,打开java.policy文件。在grant的括号中填写
permission java.io.FilePermission "<<ALL FILES>>", "read,write";
本机修改的结果就是:
// Standard extensions get all permissions by default
grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};
// default permissions granted to all domains
grant {
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See " http://java.sun.com/notes " for more information.
permission java.lang.RuntimePermission "stopThread";
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";
// "standard" properies that can be read by anyone
permission java.util.PropertyPermission "java.version", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "java.vendor.url", "read";
permission java.util.PropertyPermission "java.class.version", "read";
permission java.util.PropertyPermission "os.name", "read";
permission java.util.PropertyPermission "os.version", "read";
permission java.util.PropertyPermission "os.arch", "read";
permission java.util.PropertyPermission "file.separator", "read";
permission java.util.PropertyPermission "path.separator", "read";
permission java.util.PropertyPermission "line.separator", "read";
permission java.util.PropertyPermission "java.specification.version", "read";
permission java.util.PropertyPermission "java.specification.vendor", "read";
permission java.util.PropertyPermission "java.specification.name", "read";
permission java.util.PropertyPermission "java.vm.specification.version", "read";
permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
permission java.util.PropertyPermission "java.vm.specification.name", "read";
permission java.util.PropertyPermission "java.vm.version", "read";
permission java.util.PropertyPermission "java.vm.vendor", "read";
permission java.util.PropertyPermission "java.vm.name", "read";
permission java.io.FilePermission "<<ALL FILES>>", "read,write";
};
这样就可以让applet读写本地文件了。
http://www.javaeye.com/topic/334220
代码没有问题,是java.policy配置文件没配置好.修改配置文件就行.打开java.policy文件,在最后添加上如下代码就OK:
文件一般在下面目录下:jre/lib/security/java.policy
添加代码:
permission java.security.AllPermission;
permission java.net.SocketPermission "200.200.200.66:8000","accept,connect,listen,resolve";
就OK.因为applet有它设置的安全级别.如果你没有允许的话,就不允许你操作你电脑上的文件和其它东西.