logo_michael-thomas.jpg (3143 bytes)

Java PlugIn & PolicyTool
(Applet writes to a local file)

Click here to download the file involved in this example.
JavaScript w/Applet writes to a local file via using Java Plug-In and a policy file.
Currently works with IE only.
MyAppletWriteFile_javaplugin.html
Example of JavaScript interfacing to an Applet that will read & write to the users local file system.  A policy needs to be created by the user that allows the applet to write/read to that directory.
Steps
When you run this example, I will want to download the Java Plug-in 1.3.0_01 from Sun's site.
Note:  It looks like you must have this version.  Not an earlier or later version.  I'm not sure why Sun (or whoever) has designed it this way.
At the DOS prompt, execute the program:  policytool.exe
When you installed the Java Plug-in (includes JRE) this program was installed also.  If you get a bad command, you may want to specify the full pathname.
Ex:  C:\Program Files\JavaSoft\JRE\1.3.0_01\bin\policytool.exe
Policy Tool Steps: Create a policy file, if one does not exist.
The first time you run policytool.exe you may get an error: Could not find policy file: <file name>.  That's OK.  Make sure you right down the full pathname of the file name it is looking for.  
Ex:  c:\winnt\Profiles\<your user id>\.java.policy
If you did not have a policy file, the click on File, Save.
Next type in the policy file name as it appeared in the error.
Now you have a policy file in the default location.
Policy Tool Steps:  Create appropriate policies.
Click on "Add Policy Entry"
CodeBase = file:/c:/test
Signed By: <leave blank>
Click on "Add Permission" to add the following permissions.
File Permission to Read & Write.
FilePermission
Target Name: c:/test/MyAppletWriteFile.txt 
read, write
Click on "OK"
(Optional) Property Premissions - If you plan to use the link that runs  getDebugProperties(), you will need to add the following permissions:
PropertyPermission, user.home, read
PropertyPermission, java.home, read
Click on "Done"
File, Save.
Now in your Windows Explorer, launch the web page:  MyAppletWriteFile.html in the c:\test directory.
Warning:  While testing, if you make any changes to the policy file you must exit all browser windows, then reopen the browser and then the web page.
On this new web page, click on the first 3 links under "Using JavaScript with Java Plug-in: (works w/IE)"
The 4th link will give Security Errors unless you create the PropertyPermissions listed above.
Once you are successful with the above steps, you may try to setup the policy tool to allow my web page to write to your c:\test directory.
Click Here to launch the same web page from my site.
Hint:  Set up the same permissions above.  You will need to add another policy entry and use the following CodeBase:
http://www.michael-thomas.com/java/javaadvanced/security/javaplugin