This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Applets and the fly likes Writing to a file from an Applet using IE5, can it be done Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Writing to a file from an Applet using IE5, can it be done" Watch "Writing to a file from an Applet using IE5, can it be done" New topic

Writing to a file from an Applet using IE5, can it be done

Martin Lawrence

Joined: Oct 20, 2000
Posts: 14
Hi All,
I attempted to run the following code via IE5 after building it
under JDK1.3. I got a security exception.
I created a Ploicy file using the standard policytool command.
I set the policy settings as :-
Target Name << <<ALL FILES>> >>
Actions read, write, delete, execute
I saved the policy file as mypolicy under directory
The above directory also contains, WriteFile.class
and JavaSecurity.html.
I also added the following line:-
within file within directory:-
import java.awt.*;
import java.lang.*;
import java.applet.*;
public class WriteFile extends Applet {
String myFile = "writetest";
File f = new File(myFile);
DataOutputStream dos;
public void init() {

String osname = System.getProperty("");
public void paint(Graphics g) {
System.out.println("Start of paint");
try {
dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myFile),128));
dos.writeChars("Cats can hypnotize you when you least expect it\n");
g.drawString("Successfully wrote to the file named " + myFile + " -- go take a look at it!", 10, 10);
catch (SecurityException e) {
g.drawString("writeFile: caught security exception: " + e, 10, 10);
catch (IOException ioe) {
g.drawString("writeFile: caught i/o exception", 10, 10);
System.out.println("End of paint");
<TITLE>Java Security Model</TITLE>
<APPLET CODE="WriteFile.class" WIDTH="150" Height="25">

Help, is it possible to read/write to a file via an applet using IE5 ???
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
NO that won't work.
What you need to do is to use the JDK plug-in to your browser and configure the security setting there. And you have to use signed applets. It is a long story, but you can find it in any good book like Core Java, and I think on this ranch in some post.
I agree. Here's the link:
subject: Writing to a file from an Applet using IE5, can it be done
It's not a secret anymore!