Skip to content

Instantly share code, notes, and snippets.

@nbhusare
Last active November 24, 2018 16:43
Show Gist options
  • Select an option

  • Save nbhusare/67c589b7da426d82d6bee4dd5154a552 to your computer and use it in GitHub Desktop.

Select an option

Save nbhusare/67c589b7da426d82d6bee4dd5154a552 to your computer and use it in GitHub Desktop.
Eclipse - Reading files from a folder present in a bundle
public static List<File> getFilesFromBundle(final Bundle bundle, final String folderName) {
final List<File> files = Lists.newLinkedList();
final Enumeration<URL> findEntries = bundle.findEntries("/" + folderName, "*", false); // recursive = false
while (findEntries.hasMoreElements()) {
final URL url = findEntries.nextElement();
try {
final URL fileURL = FileLocator.toFileURL(url);
final File file = new File(fileURL.getFile());
files.add(file);
} catch (final IOException e) {
throw new RuntimeException("Error reading file from the bundle " + bundle.getBundleId(), e);
}
}
return files;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment