Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-17-2009, 07:33 AM   #1
Registered: Feb 2005
Location: agra,india
Distribution: FC2
Posts: 158

Rep: Reputation: 30
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
Old 07-17-2009, 09:28 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.

Put a debug statement in your 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

Here's code for reading a local file from a Java applet:

Last edited by paulsm4; 07-17-2009 at 09:30 AM.
Old 07-20-2009, 01:58 PM   #3
Registered: Feb 2005
Location: agra,india
Distribution: FC2
Posts: 158

Original Poster
Rep: Reputation: 30
thanks ,issue resolved , getResource worked out


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
set up java_home path in /home/user/.bashrc but use path in /usr/lib/java vitalstrike82 Slackware 4 01-13-2009 11:25 PM
Image Path reference in Linux (Absolute path) javabuddy Linux - General 7 06-05-2006 07:45 AM
relative to absolute path vishalbutte Programming 4 01-14-2006 03:17 PM
relative/absolute paths in Java djgerbavore Programming 2 10-26-2004 08:01 PM
Loading Suse Linux 9.0 loads to the point of ramdisk:Compressed image found at block0 todd1234 Linux - Newbie 7 02-24-2004 06:28 AM

All times are GMT -5. The time now is 06:48 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration