Skip to content

Instantly share code, notes, and snippets.

@dehidehidehi
Created May 9, 2023 20:37
Show Gist options
  • Save dehidehidehi/cd623ab9968de440af9b6bc1ca1db4f2 to your computer and use it in GitHub Desktop.
Save dehidehidehi/cd623ab9968de440af9b6bc1ca1db4f2 to your computer and use it in GitHub Desktop.
Utility for iterating over a folder located in the resources folder in Java.
/**
* Utility for iterating over a folder located in the resources folder.<br>
* Methods using this method are responsible for closing or operate on the stream.
*/
private static Stream<Path> getResourceFolderFiles (String folder) throws IOException, URISyntaxException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final URI uri = Objects.requireNonNull(loader.getResource(folder)).toURI();
final String path = Paths.get(uri).toString();
return Files.walk(Paths.get(path));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment