The method FileLocator.resolve(url)
can be used to translate an address bundleentry://something/somewhere/x.txt
to a proper file URL for /mnt/foo
Two additional notes:
URI resolvedUri = URI.createFileURI(resolved.getPath());
To get the file name, call resolvedUri.toFileString();
I just found this code:
http://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/model/BundledSystemLibrary.java?r=2057
The relevant lines indeed help:
// We need to use the 3-arg constructor of URI in order to properly escape file system chars.
URI resolvedUri = new URI(resolvedUrl.getProtocol(), resolvedUrl.getPath(), null);
From Vogella Blog:
URL url;
try {
url = new
URL("platform:/plugin/de.vogella.rcp.plugin.filereader/files/test.txt");
InputStream inputStream = url.openConnection().getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
To get the URL, Following can be used:
Bundle thisBundle = FrameworkUtil.getBundle(getClass());
URL fileURL = thisBundle.getEntry("<relative_file_path_from_project_root");
Also, one can choose the type of Stream/Reader to read image/text.