Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
Last active November 11, 2021 12:21
Show Gist options
  • Save sleepless-se/7b75f856abf35d00e9fc7ff0e5927a51 to your computer and use it in GitHub Desktop.
Save sleepless-se/7b75f856abf35d00e9fc7ff0e5927a51 to your computer and use it in GitHub Desktop.
How to get absolute file path in .jar file
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();
}
}
@sleepless-se
Copy link
Author

How to get absolute file path in .jar file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment