LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   java applet not loading image with relative path but loads image with absolute path (http://www.linuxquestions.org/questions/programming-9/java-applet-not-loading-image-with-relative-path-but-loads-image-with-absolute-path-740755/)

amolgupta 07-17-2009 07:33 AM

java applet not loading image with relative path but loads image with absolute path
 
java applet not loading image with relative path(e.g. images/1.jpg) but loads image with absolute path(i.e. from /root/user/images/1.jpg) . This is a problem when i want to host the applet on web server

paulsm4 07-17-2009 09:28 AM

A couple of problems/questions here:

1. If this is really an "applet"...
... then it's executing on the *client's* PC...
... and the client won't necessarily have an "images/" directory.

2. You're assuming that the Java program's working directory is "/root/user". This *isn't* necessarily true.

SUGGESTION:
Put a debug statement in your code:
Code:

String dir = System.getProperty("user.dir");
Once you know what the *actual* directory is, see if relative paths now work (e.g. "../images/1.jpg" instead of "images/1.jpg).

'Hope that helps .. PSM

PS:
Here's code for reading a local file from a Java applet:
http://www.captain.at/programming/java/

amolgupta 07-20-2009 01:58 PM

thanks ,issue resolved , getResource worked out


All times are GMT -5. The time now is 11:22 AM.