Last active
November 24, 2018 16:43
-
-
Save nbhusare/67c589b7da426d82d6bee4dd5154a552 to your computer and use it in GitHub Desktop.
Eclipse - Reading files from a folder present in a bundle
This file contains hidden or 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
| 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