AccessControlException

Hi,

I wrote an applet that is supposed to open and read a file from its own code base. I thought applets could read files that are in their code base.

Here's how I attempt to open the file:

File f = new File (getCodeBase().toString()+"newfile.txt");

BufferedReader r = new BufferedReader ( new FileReader (f));

I thought my applet would work but instead I get the following error message:

java.security.AccessControlException: access denied (java.io.FilePermission file:\C:\HASTOPLKJR\newfile.txt read)

at java.security.AccessControlContext.checkPermission(Unknown Source)

at java.security.AccessController.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkRead(Unknown Source)

at java.io.FileInputStream.<init>(Unknown Source)

at java.io.FileReader.<init>(Unknown Source)

at GJApplet$GPanel.openFile(GJApplet.java:99)

at GJApplet$GPanel.<init>(GJApplet.java:43)

at GJApplet.init(GJApplet.java:24)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Can anyone help me?

thanks a lot!

[1236 byte] By [JSecond2Nonea] at [2007-10-1 17:40:11]
# 1
> I thought applets could read files that are in their code base.Applets can connect to the server the applet came from, they can never read files (with the File object).URL u = new URL(this.getCodeBase(),"newfile.txt");
harmmeijera at 2007-7-11 3:58:21 > top of Java-index,Security,Signed Applets...