0

I'm using the URL class in a program to load a bitmap image and I was wondering if Java will recognize ../ to exit the current directory like CSS and HTML or there is another way to accomplish this.

Here's the code segment to illustrate my question:

zombieOneRight = Zkit.getImage(getURL("../_images/_production_images/zombie_1_right_75h.png")); // will the ../ work here


private URL getURL(String filename)
{
    URL url = null;
    try
    {
        url = this.getClass().getResource(filename);
    }
    catch (Exception e) {}
    return url;
}
Trein
  • 3,658
  • 27
  • 36
  • 3
    It never hurts to try. Making a small program to test something out can be a very valuable way to learn how things work. – Dennis Meng Feb 23 '14 at 05:10
  • @DennisMeng cant you use the absolute path? or absolute path from your project folder? – Srikar Appalaraju Feb 23 '14 at 05:12
  • 2
    @SrikarAppal Probably. All I'm saying is that it doesn't hurt to write a small program to test a theory out if you're not sure whether something works. Now, if the question is whether or not something is *guaranteed* to work (after having tested it and found it doing what you wanted), that's another story itself. – Dennis Meng Feb 23 '14 at 05:14

1 Answers1

0

You should be able to use the way you have it.

If it doesn't work out, try absolute path.

There is a similar question, try to follow this.

Parent parent directory in Java

Community
  • 1
  • 1
thestar
  • 4,959
  • 2
  • 28
  • 22