Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getting the parent path using getResource()

807597Jun 2 2005 — edited Jun 20 2005
i'm having problem of getting the path of the parent directory

example:
[HelloWorld]
    |----[file]
    |         |---- PersonalizedMsg.txt
    |----[classes]
              |----HelloWorld.class
what i want to do is get the URL (path) to the files directory...like C:/HelloWorld/files/

iwhat i'm doing now is
String path = HelloWorld.class.getResource("./").getPath();
this will return the C:HelloWorld/classes/

however..i can't seem to go one level up (to the parent directory of [HelloWorld]

i tried with
String path = HelloWorld.class.getResource("../").getPath();
and
String path = HelloWorld.class.getResource("./../").getPath();
to get c:/HelloWorld/
but it return null;

any help would apperciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2005
Added on Jun 2 2005
4 comments
1,054 views