I've trying to read and write a file from an applet so if I run the applet from my appletviewer开发者_如何学C 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?
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:
- How can an Applet read files on the local file system (from coderanch.com)
- Essentials, Part 1, Lesson 6: File Access and Permissions (from oracle)
- Chapter 10: Signed Applets (from oracle)
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.
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.
精彩评论