Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problems reading a properties file in an applet

Reply
Thread Tools

Problems reading a properties file in an applet

 
 
steen
Guest
Posts: n/a
 
      01-08-2007
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

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-08-2007
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.

 
Reply With Quote
 
 
 
 
steen
Guest
Posts: n/a
 
      01-09-2007


> 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

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-09-2007

steen wrote:
> > 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.


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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with file .properties in Applet Roberto Druetto Java 0 07-29-2005 03:09 PM
Problems reading file from Applet Marcus P Java 1 02-08-2005 11:34 PM
Java applet failed when I try to load the avi file in my java applet Krista Java 3 09-15-2004 02:53 AM
Problems parsing when Properties.dtd.properties Kent Lichty Java 0 04-16-2004 03:08 PM
Unable to access properties file from an applet through a proxy server Sudipto Dey Java 0 07-24-2003 08:54 AM



Advertisments