4

I've trying to read and write a file from an applet so if I run the applet from my appletviewer it is possible for me to read/write a file but when I try to do it from my browser I get a security exception. Any idea how to do this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

3 Answers3

5

Is it possible to read/write a file from an applet

Yes, but you need to sign the applet and get approval from the user.

Some useful links:

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • It's not trivial, but it's not difficult ;-) You could consider using java webstart instead. I think it is slightly simpler. – aioobe Sep 13 '11 at 18:57
1

A sand-boxed JWS app. can read and write to files on the local file system using the JNLP API services. Here is a demo. of the JNLP API file services. The downloadable Zip file contains the source, launch file and build script.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

it's actually not that difficult. You can self sign an applet and then it will be able to read/write to/from the local file system outside the sandbox constraints. take look at the link below. it will show you how to sign your applet using the keytool and the example actually does read/write to the filesystem. no need to muck about the policy files and such.

Note that as @aioobe mentioned, the user will be prompted to accept the certificate though.

Kash22
  • 111
  • 2
  • 7
  • forgot the link :) http://www.developer.com/java/other/article.php/3303561/Creating-a-Trusted-Applet-with-Local-File-System-Access-Rights.htm – Kash22 Sep 13 '11 at 21:21