This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "read and write files using applet " Watch "read and write files using applet " New topic
Author

read and write files using applet

navish kumar
Greenhorn

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: 169
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
Greenhorn

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. www.i2Brain.com/appletI2Brain.html.
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".
 
Consider Paul's rocket mass heater.
 
subject: read and write files using applet
 
Similar Threads
passing in memory file to applet
Reading A file from an Applet
writing and reading from a existing file
Loading Policy File from Applet
does anyone use the .java.policy file?