How do I extract the folder of the running Jar file? The following code gives me the path to the jar itself -- Eg. C://MyProgram/myJar.jar
... but I want only the path to the folder it is located in, so C://MyProgram/
new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath())
I have now tried one suggestion of using getParent() as such:
Path p = new Path(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent();
File f = new File(p.toString());
But Java throws an exception as the path cannot be parsed due to illegal characters in the path.