logo_michael-thomas.jpg (3143 bytes)

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

bulletClick here to download the file involved in this example.
bulletJavaScript w/Applet writes to a local file via using Java Plug-In and a policy file.
Currently works with IE only.
Java Security Example- Writing Files
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
bulletWhen 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.
bulletAt the DOS prompt, execute the program:  policytool.exe
bulletWhen 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
bulletPolicy Tool Steps: Create a policy file, if one does not exist.
bulletThe 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
bulletIf you did not have a policy file, the click on File, Save.
bulletNext type in the policy file name as it appeared in the error.
bulletNow you have a policy file in the default location.
bulletPolicy Tool Steps:  Create appropriate policies.
bulletClick on "Add Policy Entry"
bulletCodeBase = file:/c:/test
bulletSigned By: <leave blank>
bulletClick on "Add Permission" to add the following permissions.
bulletFile Permission to Read & Write.
bulletFilePermission
bulletTarget Name: c:/test/MyAppletWriteFile.txt 
bulletread, write
bulletClick on "OK"
bullet(Optional) Property Premissions - If you plan to use the link that runs  getDebugProperties(), you will need to add the following permissions:
bulletPropertyPermission, user.home, read
bulletPropertyPermission, java.home, read
bulletClick on "Done"
bulletFile, Save.
bulletNow 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.
bulletOn this new web page, click on the first 3 links under "Using JavaScript with Java Plug-in: (works w/IE)"
bulletThe 4th link will give Security Errors unless you create the PropertyPermissions listed above.
bulletOnce 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