aspose file tools*
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 Spring in Action this week in the Spring 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
Author

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

Martin Lawrence
Greenhorn

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 :-
FilePermission java.io.FilePermission
Target Name << <<ALL FILES>> >>
Actions read, write, delete, execute
I saved the policy file as mypolicy under directory
C:\JavaExamples\SecurityApplet\
The above directory also contains WriteFile.java, WriteFile.class
and JavaSecurity.html.
I also added the following line:-
policy.url.3=file:c:/javaExamples/SecurityApplet/mypolicy
within file java.security within directory:-
c:\jdk1.3\jre\lib\security
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");
dos.flush();
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");
}
}
<HTML>
<HEAD>
<TITLE>Java Security Model</TITLE>
</HEAD>
<APPLET CODE="WriteFile.class" WIDTH="150" Height="25">
</APPLET>
<HR>
</BODY>
</HTML>

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.
 
jQuery in Action, 2nd edition
 
subject: Writing to a file from an Applet using IE5, can it be done