Skip to main content
deleted 1 character in body
Source Link
peterh
  • 1
  • 20
  • 89
  • 113
return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation() .toURI()).getPath(); 

Replace "MyClass" with the name of your class.

Obviously, this will do odd things if your class was loaded from a non-file location.

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

Replace "MyClass" with the name of your class

Obviously, this will do odd things if your class was loaded from a non-file location.

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

Replace "MyClass" with the name of your class.

Obviously, this will do odd things if your class was loaded from a non-file location.

added 12 characters in body
Source Link
djangofan
  • 29.9k
  • 62
  • 211
  • 308
return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation() .toURI()).getPath(); 

Replace "MyClass" with the name of your class

Obviously, this will do odd things if your class was loaded from a non-file location.

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

Replace "MyClass" with the name of your class

Obviously, this will do odd things if your class was loaded from a non-file location.

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

Replace "MyClass" with the name of your class

Obviously, this will do odd things if your class was loaded from a non-file location.

An additional closing parenthesis was needed betwen .toURI() and before .getPath
Source Link
return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath()); 

Replace "MyClass" with the name of your class

Obviously, this will do odd things if your class was loaded from a non-file location.

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

Obviously, this will do odd things if your class was loaded from a non-file location.

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

Replace "MyClass" with the name of your class

Obviously, this will do odd things if your class was loaded from a non-file location.

.toURI() was placed in the wrong spot. Compiler warnings are thrown the other way around.
Source Link
Loading
As pointed out in the comments, this WILL NOT work with spaces, and I don't want to have to read through the comments to find the fix anymore
Source Link
Loading
added 1 characters in body
Source Link
Kerem Baydoğan
  • 10.8k
  • 1
  • 45
  • 53
Loading
Source Link
Zarkonnen
  • 22.6k
  • 14
  • 70
  • 82
Loading