Is it possible to get the file name which is being executed. Like e.g. If i am running a Jar file, and inside i want to add code functionality that can detect the file name so that if this jar is renamed, code should be able to detect that.
Is there any possibility of doing this without scanning the files in current directory?
Try this:
String path = Test.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(path, "UTF-8");
http://www.rgagnon.com/javadetails/java-0300.html
http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getProtectionDomain()
http://docs.oracle.com/javase/7/docs/api/java/security/ProtectionDomain.html
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