Signed Applet access to local files when a strange question, experts advise

Category: Java Related
 
bulage7hao
2013-08-19 10:26:26

Sponsored Links
I wrote two Applet
a code is as follows:
import java.io. *;
import java.awt. *;
Import java.applet. *;
public class AppletShowFile extends Applet {
String content = "The content of file:";
; TextArea ta = new TextArea (10,80);

public void init () {
; String s;
; BufferedReader in;
try {
; in = new BufferedReader (new FileReader ("c: \ \ AUTOEXEC. bat "));
while ((s ; = in.readLine ())! = null) {
; content + = s + "\ n";
;}
}
catch (Exception e) {
System.err.println (e);
;}
add (ta);
}
public void paint (Graphics g) {
; ta.setText (content);
}
}
This Applet is digitally signed able to obtain the contents of the local file
Again, I wrote another piece of code, in which the access code is not on the local file init () function, but on the preparation of their own function, as follows:
import java.io. *;
import java.awt. *;
import java.applet. *;

public class SignApplet extends Applet
{
String text = "Hello!" ;/ / remove the text of the public property
String s = " 2 ";
public void paint (Graphics g)
{g.drawString (text, 80,80);}

/ / Here add a public function
public void Set ()

{

String s;
BufferedReader in
try {
in = new BufferedReader (new FileReader ("c: \ \ AUTOEXEC.bat"));
while ((s = in.readLine ())! = null) {
text + = s + "\ n"; }
catch (Exception e) {
text = e.toString ();
}
repaint ();
}
}

I called out in the program This signature Applet after the Set () function, the following error appears
java.security.AccessControlException: access denied (java.io.permission c: \ AUTOEXEC.bat read
Can not read local files
what is the problem! Need help! Thank


Sponsored Links

wujizhilu
2013-08-19 10:35:10
you to configure the look jre java.policy file so that it has access to the file permissions
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.