I've got a little script I'm using a paramter to pass in the current execution directory, but would like to make it a little more robust.
How does one find out the base execution directory?
In Java, we can use System. getProperty("user. dir") to get the current working directory, the directory from where your program was launched.
dir". This is used as a base for the "File" object so if you System.
The current working directory is c:\JavaProgram. Now let us understand the above program. The current working directory is obtained by using the key user.dir with the method java.lang.System.getProperty().
Since the path changes machine to machine, you need to use a variable / project level property, say BASE_DIRECTORY, set this value according to machine, here "/home/vishalpachupute" and rest of the path maintain the directory structure for the resources being used. Regards, Rao.
Try this:
System.getProperty("user.dir");
Depending on the security model, if the System.getProperty(String)
is not allowed, you can use
String currentDir = new File(".").getAbsolutePath()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With