2013-04-23 42 views
0

我正在使用以下代碼將插件「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

你所說的「插件」是什麼意思? – cahen 2013-04-23 12:22:34

+0

我正在開發eclipse rcp插件項目。 – MIM 2013-04-23 12:42:30

回答

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)); 
+0

非常感謝。有效 – MIM 2013-04-24 08:24:13

相關問題