I am using following code to copy icons which are available in resource folder of Plug-in "A" to a local folder. This works absolutely fine. Now I want to know if there is way to copy icons from resource folder of other plugin say (plugin B). I have to retain the copy logic in plugin A only. Is there a way to access the resource folder of other plugin from current plug-in ?
File objectDir = new File(directory + "/icons/");
if (!objectDir.exists()) {
objectDir.mkdirs();
}
InputStream inStream = null;
OutputStream outStream = null;
try {
File bfile = new File(directory + "/icons/validation.png");
inStream = this.getClass().getClassLoader().getResourceAsStream("/icons/viewAsHTML.png");
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
// copy the file content in bytes
while ((length = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
System.out.println("File is copied successful!");
} catch (IOException e) {
e.printStackTrace();
}
You should be able to get at a resource in another plugin by using the platform:/plugin/
mechanism:
url = new URL("platform:/plugin/your.plugin.package.pluginB/icons/validation.png");
InputStream inputStream = url.openConnection().getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));