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

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