Click to See Complete Forum and Search --> : Relative paths in windows?
DodgerLD
April 6th, 2004, 03:34 PM
Hi,
I'm using:
ImageIcon default_icon = new ImageIcon("images/0.png");
And it works fine in Linux, but not in Windows. When I specify an absolute path, it works in Windows as well.
Are relative paths not supported with Java in windows?
...or am I missing something?
TIA.
D.
Joe Nellis
April 6th, 2004, 05:51 PM
I believe it relies upon the CWD or current working directory. It depends on how/where you execute the .class file. If you are trying to execute your program from the java bin directory then you will get the file not found error because the CWD is the bin directory.
This should work from a command prompt.
c:\myjavafiles> c:\pathtojava\bin\java myprogram.class
You should set the PATH environment variable for windows to include the bin directory so you can just say...
c:\myjavafiles> java myprogram.class
http://java.sun.com/j2se/1.4.2/install-windows.html
Joe Nellis
April 6th, 2004, 06:07 PM
I want to add that the following Windows reg hack is really useful for developers. It allows you to open a command prompt by right clicking on a folder in windowsexploder and the command prompt will default to that directory.
http://windows.about.com/library/tips/bltip177.htm
cjard
April 7th, 2004, 03:02 PM
Originally posted by DodgerLD
Hi,
I'm using:
ImageIcon default_icon = new ImageIcon("images/0.png");
And it works fine in Linux, but not in Windows. When I specify an absolute path, it works in Windows as well.
Are relative paths not supported with Java in windows?
...or am I missing something?
TIA.
D.
examine this, as an addendum to joes post mentioning the current directotry:
http://java.sun.com/docs/books/tutorial/essential/system/properties.html
DodgerLD
April 10th, 2004, 08:07 AM
Thanks for the info guys.
I thought it might have something to do with my use of the Eclipse platform, so I tried running it from the command prompt, and sure enough it worked.
It seems I don't have it setup correctly and it's not seeing the images directory through Eclipse. It's not serious, but if you do have any ideas, please let me know.
Thanks again,
D.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.