My java file is in harness folder. I need absolute path of folder bif_v3 which is inside parent directory.
Asked
Active
Viewed 828 times
-6
-
2Search first before asking questions. A simple google search of the question gives this http://www.tutorialspoint.com/java/io/file_getabsolutepath.htm – javaDeveloper Aug 29 '16 at 13:00
-
Blatantly off-topic (this question has nothing to do with programming). Please have a look at [ask] and [mcve] – xenteros Aug 29 '16 at 13:14
-
What is the reason, that you have tagged your question `java`? The fact that your file is `outside workspace in java`? Does it mean, that if it was inside java workspace, you wouldn't tag it as `java`? – xenteros Aug 29 '16 at 13:16
-
1@RakeshNair OP didn't say that he wants to do that programmaticaly – xenteros Aug 29 '16 at 13:17
1 Answers
1
Although you didn't ask certainly what you want to do, I assume that you want to open a file programmatically from a file which is in harness
. You can 'navigate' programmatically using the following methods:
File currentDir = new File("."); //this will be your current directory
File parentDir = currentDir.getParentFile(); //this is parent directory
File newFile = new File(parentDir,"Example.txt"); //this is file Example.txt placed in parent directory
File newFile = new File(parentDir,"bif/Example.txt"); //this is file Example.txt placed in parent directory's directory bif.

xenteros
- 15,586
- 12
- 56
- 91
-
The way of obtaining the parent directory that you proposed gave me a null pointer exception. What worked for me is the following: `File parentDir = currentDir.getAbsoluteFile().getParentFile();`, as per [this answer](https://stackoverflow.com/a/11297046/7305715). – asymmetryFan Jun 19 '20 at 20:17