Created
May 9, 2023 20:37
-
-
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.
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
/** | |
* 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