CodeBlue CodeBlue - 1 year ago 129
Java Question

How to write path such that you first go up a directory up and then down into other directories?

I am trying to open a file in a Java program (say using relative path.

I have two directories as follows


Now, from, I want to write a relative path to access SC01.txt

String path = // <-- not sure how to write the path
File scenario = new File (path);

The path has to be such that I go one level up to the ProjectWork directory and then navigate to Scenarios\SC01.txt.

Please help. Thanks.

Answer Source

From what you are saying, you should set path to:


../ to go up one level then the rest is the relative path against ProjectWork

In Java file when you use a relative path without another argument, the file is matched against the System property user.dir which matches the working directory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download