Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Create a file in the workspace
Create a file in the workspace [message #309990] Tue, 14 November 2006 18:05 Go to next message
Eclipse User
Originally posted by: dorazio.nicola.yahoo.it

Hi all,
first sorry for my bad English and for my incompetence. I'm making a
plug-in that when you make an action it create a file into the workspace
in which the file you have selected is located. My problem is to
obtain the full path to set correctly the constructor of
FileOutputStream class. How can i do?

Thanks all for help and for time give to me.

Nicola
Re: Create a file in the workspace [message #309994 is a reply to message #309990] Tue, 14 November 2006 20:14 Go to previous messageGo to next message
Gail Jakubowski is currently offline Gail Jakubowski
Messages: 7
Registered: July 2009
Junior Member
Platform.getInstanceLocation().getURL() should give you the location of the
workspace.

"Nicola D'Orazio" <dorazio.nicola@yahoo.it> wrote in message
news:ejd0ho$f9g$1@utils.eclipse.org...
> Hi all,
> first sorry for my bad English and for my incompetence. I'm making a
> plug-in that when you make an action it create a file into the workspace
> in which the file you have selected is located. My problem is to obtain
> the full path to set correctly the constructor of FileOutputStream class.
> How can i do?
>
> Thanks all for help and for time give to me.
>
> Nicola
Re: Create a file in the workspace [message #309996 is a reply to message #309994] Tue, 14 November 2006 20:33 Go to previous message
Eclipse User
Originally posted by: richkulp.us.NO_SPAM.ibm.com

getInstanceLocation() is not sufficient, because the project you want to
put the file into may not be under the instance location. It may be
somewhere else.

You need to know three things:

1) What project will the file be put into
2) What directory (sub-directory) under that project it will be placed
3) The name of the file that you are creating.

Given that, then you would do (replace (1) with the name of the project,
(2) with directory, and (3) with the file name:

IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("(1)");
IFile yourFile = p.getFile("(2)/(3)");

if (yourFile.exists())
yourFile.setContents(InputStream,...)
else
yourFile.create(InputStream,...)

Create an InputStream that returns the contents that you want to have in
the file.

It is usually better to use the IFile methods than to do straight
java.io.File stuff because using the IFile methods lets Eclipse know
changes have been made immediately instead of having to be synchronized
later.

Gail Jakubowski wrote:
> Platform.getInstanceLocation().getURL() should give you the location of the
> workspace.

--
Thanks,
Rich Kulp
Previous Topic:[Activities] how to use activityPatternBinding's with one's own newly-defined extension-point?
Next Topic:Rename Action Implementation
Goto Forum:
  


Current Time: Thu Oct 30 15:13:50 GMT 2014

Powered by FUDForum. Page generated in 0.01578 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software