AccessControlException - Reading from a file on the server

I'm writing an applet that needs to read data from a file on the same web server as the applet. In this case, both the applet class and the file exist in the same .jar file on the server. I'mnot attempting to read or write to a file on alocal machine, nor am I trying to write to a file on the server.

When I attempt to run the applet on my machine or from the web, the applet loads, but fails to read the file. The Java Console dsisplays the following message:

Error: java.security.AccessControlException: access denied (java.io.FilePermission ColorMesh1.3dm read)

The code that's accessing the file looks like this:

dataFile =new BufferedReader(new FileReader(fileName));

Where the argument "fileName" is the name of the file to be read (ColorMesh1.3dm in this case).

All the resources I've been able to find seem to indicate that reading from a file on the host machine doesn't require file permissions or a security certificate. Is this assumption incorrect, or am I doing something wrong? Does it have something to do with paths?

[1171 byte] By [CalPolyDeveloper] at [2007-9-30 7:42:43]
# 1

Hi CalPolyDeveloper

You are actually reading a file from the local machine when you say, new FileReader()...

you are supposed to read a file in your jar file as

URL url=myClass.class.getResource(fileName);

then try

URLConnection con=url.openConnection();

?InputStream in=con.getInputStream();

OutputStream out=con.getInputStream();

and then use these two streams for reading and writing.

Ofcourse , some problems may come in reading and writing , but those require giving right file path.

if the file exists in the base directory in your jar file , it is the best thing .

Make sure that the jar file or the file you are writing is not read only.

Regards.....

Pavan

pav_shan at 2007-7-2 0:55:52 > top of Java-index,Security,Signed Applets...