I want to access my current working directory using java.
My code :
String current = new java.io.File( \".\" ).getCanonicalPath();
System.ou
On Linux when you run a jar file from terminal, these both will return the same String
: "/home/CurrentUser", no matter, where youre jar file is. It depends just on what current directory are you using with your terminal, when you start the jar file.
Paths.get("").toAbsolutePath().toString();
System.getProperty("user.dir");
If your Class
with main
would be called MainClass
, then try:
MainClass.class.getProtectionDomain().getCodeSource().getLocation().getFile();
This will return a String
with absolute path of the jar file.