Skip to content

Instantly share code, notes, and snippets.

@StasKolodyuk
Created April 29, 2017 16:17
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 StasKolodyuk/0ff9dd908b2f39a9c31e361594f000f8 to your computer and use it in GitHub Desktop.
Save StasKolodyuk/0ff9dd908b2f39a9c31e361594f000f8 to your computer and use it in GitHub Desktop.
public static void copyDirectoryFromResources(String source, final String target) throws IOException {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(source + "/**");
for (Resource resource : resources) {
if (resource.isReadable() && resource.contentLength() > 0) {
String relativePath = StringUtils.substringAfter(resource.getURL().toExternalForm(), source);
FileUtils.copyURLToFile(resource.getURL(), new File(target, relativePath));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment