Manish said:
???
I think it is the later. Let me try again -
I have pacakge say com.some_package
and I have this code in the file which is in this package.
URL u = SomeClass.class.getResource("../../images/pic.gif");
With this I get URL as "null", obviously I can't invoke toString on
null. When I do this, it works and gives me a proper URL -
URL u =
SomeClass.class.getResource("com/some_package/images/pic.gif");
So I am aware of the problem, due to dots not getting resolved the
way I anticipate them.
And I want to understnad what exactly is the resource the code -
SomeClass.class.getResource("../../images/pic.gif");
is trying to get.
If the getResource() works as I think, it
would check for such '../' early and simply
return 'null' without even looking.
[ 'I look into the source code/JLS gurus'*
feel free to correct me here. ]
It is important to note that you should not
need to express it either of these ways. I
suspect you must not have seen my first post
on this (this is my 3rd post in this thread)
as I see no reference to you trying what I
suggested in 1st post.
SomeClass.getClass().getResource("images/pic.gif");
That should work even if 'images' directory
is deep inside a package structure. In fact,
if pic.gif is the _only_ gif of that name on the
classpath, this should work as well..
SomeClass.getClass().getResource("pic.gif");
.. Is it
com/some_package../../images/pic.gif ? (After reading JavaDoc, I
think ths is what it is trying by prepending package name to it).
* If you are really that interested how Sun
codes the core classes, are running late model
Windows (I run XP) and have the 'full Java install',
try 'Search...'ing the Java directory (e.g. C://j2sdk1.4.2_02/)
for Class.java, it should be found inside the ..
'whatever it is'.jar (shrugs, Winblows finds
it, but does not report the name of the jar??)
A cursory look at the source (all I have time
for) seems to suggest to me that Sun is only
prepending the package name if you start
the string "/images/pic.gif".
If yes, then I would like to print the same. How????
Hope I made it clear this time.
You are asking where Java looks
in that situation? That sounds to me
like asking how you spell 'Java' in the
fourth dimension, Manish. ;-)
With a well formed resource name it
would check all the directories/jars
listed on the class path, not just 'a'
place.
I feel your question (as I now
understand it) is best answered with
'use a valid path before worrying
about such minor technicalities'.
(shrugs) I hope that makes it a bit
more clear for you, and that it helps,
but if you are that keen to find out
what Java does, examine the source.