Problems reading a properties file in an applet

Discussion in 'Java' started by steen, Jan 8, 2007.

  1. steen

    steen Guest

    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
     
    steen, Jan 8, 2007
    #1
    1. Advertising

  2. 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.
     
    Andrew Thompson, Jan 8, 2007
    #2
    1. Advertising

  3. steen

    steen Guest


    > 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
     
    steen, Jan 9, 2007
    #3
  4. 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.
     
    Andrew Thompson, Jan 9, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. starwiz
    Replies:
    4
    Views:
    2,242
    starwiz
    Feb 6, 2005
  2. Sudipto Dey
    Replies:
    0
    Views:
    653
    Sudipto Dey
    Jul 24, 2003
  3. Kent Lichty
    Replies:
    0
    Views:
    843
    Kent Lichty
    Apr 16, 2004
  4. Krista
    Replies:
    3
    Views:
    2,331
    Andrew Thompson
    Sep 15, 2004
  5. Marcus P
    Replies:
    1
    Views:
    392
    The Abrasive Sponge
    Feb 8, 2005
Loading...

Share This Page