• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Martin Lawrence
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :-
FilePermission java.io.FilePermission
Target Name << <<ALL FILES>> >>
Actions read, write, delete, execute
I saved the policy file as mypolicy under directory
The above directory also contains WriteFile.java, WriteFile.class
and JavaSecurity.html.
I also added the following line:-
within file java.security within directory:-
import java.awt.*;
import java.io.*;
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("os.name");
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
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!