Strange behaviour of signed applet when accessing a file

Can you advise me please, where is the problem?

I use signed applet to access a file on my HD - I use its method print_file(), see below.

When this method is called from the init() method, it works fine = the content of a file is printed into Java Console. But when applet.print_file() is called from JavaScript, I receive the following error: java.security.AccessControlException: access denied (java.io.FilePermission D:\devel\source\file.xml read).

I use MS IE 6.0 + sp1, JRE 1.4.2_03.

My html page is:

#################

<html>

<head><title>Some title</title> </head>

<body>

<hr />

<applet NAME="TestApplet02"

CODE="test.TestApplet02.class"

CODEBASE="/test"

ARCHIVE="applets/TestApplet02.zip"

WIDTH="0"

HEIGHT="0"

MAYSCRIPT >

</applet>

<script language="JavaScript">

function print_file() {

var retval = TestApplet02.print_file("D:\\devel\\source\\file.xml");

}

</script>

<div align=center>

<h3>Printing a file</h3>

<a href="javascript:void(print_file())"> Print file </a>

</div>

<hr />

</body>

</html>

#################

My TestApplet02.java is:

#################

package test;

import java.applet.Applet;

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;

public class TestApplet02 extends Applet {

public void init() {

print_file("D:\\devel\\source\\file.xml"); // this works fine, file is printed in Java Console

}

public void start() { }

public void stop() { }

public void destroy() { }

public String print_file(String filename) {

try {

FileInputStream fis=new FileInputStream(filename);

ByteArrayOutputStream tempstream = new ByteArrayOutputStream();

byte[] buf = new byte[1024];

int i;

while ((i = fis.read(buf, 0, 1024)) != -1) tempstream.write(buf, 0, i);

fis.close();

System.out.println(tempstream.toString());

return "OK";

} catch (Exception e) {

System.out.println("print_file error");

e.printStackTrace();

return("Error");

}

}

}

#################

[2384 byte] By [asdfgytuerdjflgjgvmJJa] at [2007-9-30 0:14:45]
# 1

I found out that it works fine with JRE 1.3.1_08.

Maybe it is a bug.

I tried it also with <OBJECT> tag:

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "600" HEIGHT = "125" NAME = "TestApplet02" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_0-win.cab#Version=1,4,1,mn">

<PARAM name="code" value="test.TestApplet02.class">

<PARAM NAME = ARCHIVE VALUE = "applets/TestApplet02.zip" >

<PARAM name="codebase" value="/test">

<PARAM name="type" value="application/x-java-applet;jpi-version=1.4.1">

<PARAM NAME="MAYSCRIPT" VALUE="true">

<PARAM name="scriptable" value="true">

<PARAM name="progressbar" value="false">

</OBJECT>

It works fine with <APPLET> and <OBJECT> tags and with JDK 1.3.1_08 and it always fails with JDK 1.4.2.

ntp234a at 2007-7-16 4:43:12 > top of Java-index,Security,Signed Applets...
# 2
The solution is at http://forum.java.sun.com/thread.jsp?forum=63&thread=442390Thanks to Eladio_Galvez.(It looks like a bug.)
ntp234a at 2007-7-16 4:43:12 > top of Java-index,Security,Signed Applets...