This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Applets and the fly likes read and write files using applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "read and write files using applet " Watch "read and write files using applet " New topic

read and write files using applet

navish kumar

Joined: Sep 17, 2003
Posts: 3
I have a applet basically made for a Game. I want to have a text file called hiscores which is accessed by this applet and writes the userid into this with this total no of moves made.
The applet is running fine but am not able to get the applet write into or read the file. It always says file not found.
reply me ASAP
Idly Vada
Ranch Hand

Joined: Sep 02, 2003
Posts: 135
Due to security restrictions, applets can not direcly access local file system unless they are given permissions by the user.

To enable your applet to acess the file system, you should edit the policy files and give appropriate permissions.You can do this by using policytool command or manually edit policy files.Give FilePermission(read and write) to the text file. You can give permission based on the codebase and/or signed authority.
Other approaches are: store user statistics in local variables or on the server side.
Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 170
Ive same problem. Even just reading the files in a certain directory, what do you mean policy file? is it the attribute of the file (read-only, archive ...) ? Thanks...
John Boyd-Rainey

Joined: Sep 24, 2003
Posts: 3
Assuming you want to store the data on the client:
I have a signed (but not certified) applet which happily reads and writes to the local disk, if the user agrees to let it by clicking "Yes" to the security warning while it is loading.
If you want to store the data on the server, you'll need a small CGI there to do it. Have a look at the URLConnection class and look it up in a search enging with the term "CGI".
I agree. Here's the link:
subject: read and write files using applet
It's not a secret anymore!