How to have a program print it's location?

Bob the Bob :

I have a java program and I want it to be able to print out its location on the computer. For example, if I were to place the program in the Downloads folder, and run it, it would print out the path to the file.

a8_ :
new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation()
.toURI()).getPath();

make sure to change the Myclass.class stuff

then system.out.println(File)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=379133&siteId=1