Last active
November 11, 2021 12:21
-
-
Save sleepless-se/7b75f856abf35d00e9fc7ff0e5927a51 to your computer and use it in GitHub Desktop.
How to get absolute file path in .jar file
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 class Utility { | |
public static void main(String[] args) throws Exception { | |
Utility utility = new Utility(); | |
String absolutePath = utility.getAbsolutePath("./credentials.json"); | |
} | |
public String getAbsolutePath(String relativeFilePath) throws IOException { | |
URL url = this.getClass().getResource(relativeFilePath); | |
return url.getPath(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to get absolute file path in .jar file