Skip to content

Instantly share code, notes, and snippets.

@jmewes
Created October 31, 2017 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmewes/09c188a94fc5bba10c8c48b8b1409f08 to your computer and use it in GitHub Desktop.
Save jmewes/09c188a94fc5bba10c8c48b8b1409f08 to your computer and use it in GitHub Desktop.
How to read in resources as File object?
private static File getResourceAsFile(String resourcePath) {
URL resourceUrl = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
try {
return new File(resourceUrl.toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment