Problems reading a properties file in an applet

S

steen

Hey all,

like the topic says, I have a problem reading a properties file from an
applet.

I've packed the applet into a jar which the html page then loads, but
when I try to read my version.properties file (which is in the root of
the jar-file) I get an
java.security.AccessControlException: access denied
(java.io.FilePermission version.properties read)

I'm trying to read the file using
p.load(getClass().getResourceAsStream("/version.properties"));

I am probably missing something pretty elementary, but I've gone blind
looking for the problem...any ideas ?

Thanks in advance.
/Steen
 
A

Andrew Thompson

steen wrote:
....
I've packed the applet into a jar which the html page then loads, but
when I try to read my version.properties file (which is in the root of
the jar-file) I get an
java.security.AccessControlException: access denied
(java.io.FilePermission version.properties read)

I'm trying to read the file using
p.load(getClass().getResourceAsStream("/version.properties"));

That does not add up. I cannot see why an SAE
is thrown, if reading the properties from a stream
coming from an URL pointing to wtihin one of the
Jar's that is on its own classpath.

One thing I will point out though, it is well worth
breaking the last statement down to ensure all
our assumptions are correct.

URL propertiesAddress =
getClass.getResource("/version.properties");
// where does this point?
System.out.println(
"propertiesAddress: " + propertiesAddress );
p.load( propertiesAddress.openStream() );
....
I am probably missing something pretty elementary, but I've gone blind
looking for the problem...any ideas ?

1) To fix the applet..
Provide an SSCCE*.
Provide an URL to the broken applet.

2) To deploy the code (as 'not an applet')..
Code this as a web-start application.

* <http://www.physci.org/codes/sscce>

Andrew T.
 
S

steen

URL propertiesAddress =
getClass.getResource("/version.properties");

Most excellent. This approach works, but what is the difference between
getResource("").openStream() and getResourceAsStream() ? The latter
throws the exception,the first doesnt.
1) To fix the applet..
Provide an SSCCE*.
Provide an URL to the broken applet.

Unfortunately I cant provide an url since this is an applet which runs
on an intranet.
2) To deploy the code (as 'not an applet')..
Code this as a web-start application.

I would love to, but this is a legacy system that I can't rewrite. I'm
not even allowed to restart the apache server running it.

Anyways, the approach with getResource().getStream() works, so I'm
gonna go with that.

Thanks..:)

/Steen
 
A

Andrew Thompson

steen said:
Most excellent. This approach works, but what is the difference between
getResource("").openStream() and getResourceAsStream() ? The latter
throws the exception,the first doesnt.

To be honest, I expected both forms as originally
listed, to work exactly the same. The result might
have changed if you moved the entire call from (e.g)
main() to a within a constructor, but I can see no other
reason why the code should behave differently.
(I was merely suggesting the alternate form, so we
could check where that URL pointed!)

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top