how can i overcome this problem...in applet

my applet will read in a file for data,

when i compile using JCreator, it work...

but when i open the html file to run, problems occur,

state that loading java applet failed.

the message shown in java console:

java.security.AccessControlException: access denied (java.io.FilePermission data.dat 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.FileInputStream.<init>(Unknown Source)

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

at Reader.<init>(Reader.java:9)

at Puzzle.init(Puzzle.java:30)

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

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

thanks a lot for help

[1001 byte] By [jiuhua] at [2007-11-27 7:30:24]
# 1
http://java.sun.com/developer/technicalArticles/Security/Signed/
quittea at 2007-7-12 19:10:36 > top of Java-index,Java Essentials,Java Programming...
# 2

Applets, without special arrangements, are not allowed to access files on the local machine. I mean, would you want an applet on some random web page to be able to access your files?

In any casean applet should run on anyone's machine, without requiring data files to be located and some particular place.

Read your data from the server where the applet lives e.g. using Class.getResourceAsStream().

malcolmmca at 2007-7-12 19:10:36 > top of Java-index,Java Essentials,Java Programming...
# 3
i'm using this code to read my fileBufferedReader br = new BufferedReader(new FileReader("data.txt"));how to apply?
jiuhua at 2007-7-12 19:10:36 > top of Java-index,Java Essentials,Java Programming...
# 4

As I said, you need to read it from the server. Exactly how depends on what kind of data it is. If it's always going to be the same for the program then treat it as a "resource". If it's apt to change without rebuilding the program then serve it as a regular file, and access it via. a regular URL.

Say it's a resource, place it in the same directory as the .class file that loads it and do:

InputStream ds = getClass().getResourceAsStream("data.txt");

Reader r = new InputStreamReader(ds);

BuffererdReader br = new BufferedReader(r);

malcolmmca at 2007-7-12 19:10:36 > top of Java-index,Java Essentials,Java Programming...
# 5
now i get it....thanks a lot for it.....very thank you for the help...
jiuhua at 2007-7-12 19:10:36 > top of Java-index,Java Essentials,Java Programming...