Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative file path in java

I have this code:

 Process p = Runtime.getRuntime().exec(command.toString(), null, 
                                          new File("D:\\Cognity"));

But the thing is the Cognity directory is not always in D:\, it could be in C:\ etc. So my question is if there is a way to give it a relative path so I don't have to change this code depending on the PC that uses the program?

like image 850
Schadenfreude Avatar asked Feb 12 '26 01:02

Schadenfreude


1 Answers

As System.getProperty("user.dir")); returns the directory from which the JVM was launched you still can't guarantee whether you're in C:\ or D:\ My advice would be to pass the Cognity location in as a -D commandline argument and use it like this:

Process p = Runtime.getRuntime().exec(command.toString(), null, new File(System.getProperty("cognity.dir")));

like image 101
mickfagan Avatar answered Feb 14 '26 16:02

mickfagan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!