eclipse插件運行時獲取文件路徑

通過FileSystem獲取插件運行時的文件和文件夾。

public static File toLocalFile(String folderName){  
        try {  
            URL url = Activator.getDefault().getBundle().getEntry(folderName);  
            url = FileLocator.toFileURL(url);  
            IFileSystem fs = EFS.getLocalFileSystem();  
            IFileStore file = fs.getStore(new Path(url.getPath()));  
            IFileStore fileStore = file.getFileStore(new Path(""));  
            File file2 =  fileStore.toLocalFile(EFS.NONE, null);               
            return file2;  
        } catch (IOException e) {  
            e.printStackTrace();  
        } catch (CoreException e) {  
            e.printStackTrace();  
        }  
        return null;  
    }  

需要把org.eclipse.core.filesystem這個jar包加入lib中,還要在dependencies選項卡中把這個jar包添加進去,否則會報classnotfoundexception。

轉載自:qq123zhz

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章