---
title: "How do I open an editor on a file outside the workspace?"
author: "Dollyn"
date: "2008-03-03T10:52:00Z"
tags: []
slug: "how-do-i-open-an-editor-on-a-file-outside-the-workspace"
draft: false
lastmod: "2012-02-10T09:48:39Z"
id: 1401560
url: "https://dollyn.iteye.com/blog/1401560"
---

Since 3.3 you can use the new EFS support to open an text editor on a file outside the workspace:

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)Stringname=newFileDialog(aShell,SWT.OPEN).open();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)if(name==null)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)return;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)IFileStorefileStore=EFS.getLocalFileSystem().getStore(newPath(filterPath));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)fileStore=fileStore.getChild(names\[i]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)if(!fileStore.fetchInfo().isDirectory()&&fileStore.fetchInfo().exists())...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)IWorkbenchPagepage=window.getActivePage();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)try...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)IDE.openEditorOnFileStore(page,fileStore);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}catch(PartInitExceptione)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//\*somecode\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)

Alternatively, you can create a *linked resource* in an existing project, which points to a file elsewhere in the file system. This example snippet creates a project called “External Files,” and then prompts the user to select any file in the file system. The code then creates a linked resource in the project to that external file, allowing the platform to open the file in read/write mode in one of the standard editors:

```



IWorkspacews=ResourcesPlugin.getWorkspace();
IProjectproject=ws.getRoot().getProject("ExternalFiles");
if(!project.exists())
project.create(null);
if(!project.isOpen())
project.open(null);
Shellshell=window.getShell();
Stringname=newFileDialog(shell,SWT.OPEN).open();
if(name==null)
return;
IPathlocation=newPath(name);
IFilefile=project.getFile(location.lastSegment());
file.createLink(location,IResource.NONE,null);
IWorkbenchPagepage=window.getActivePage();
if(page!=null)
page.openEditor(file);



```