Created
September 28, 2017 06:29
-
-
Save RayanFar/c594b8ceaea7c1a8da479493c8f040a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String path(Class clazz) { | |
try { | |
File tmp = new File(clazz.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); | |
String ext = tmp.getName(); | |
if (ext.contains(".jar")) { | |
String p = tmp.toString(); | |
p = p.substring(0, p.lastIndexOf(File.separator)); | |
return p + File.separator; | |
} else { | |
return p; | |
} | |
} catch (URISyntaxException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment