我使用以下代码将插件“A”的资源文件夹中可用的图标复制到本地文件夹。这绝对没问题。现在我想知道是否有办法从其他插件的资源文件夹中复制图标说(插件B)。我必须仅在插件A中保留复制逻辑。有没有办法从当前插件访问其他插件的资源文件夹?
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();
}
答案 0 :(得分:2)
您应该能够使用platform:/plugin/
机制获取另一个插件中的资源:
url = new URL("platform:/plugin/your.plugin.package.pluginB/icons/validation.png");
InputStream inputStream = url.openConnection().getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));