Create a file in the workspace [message #309990] |
Tue, 14 November 2006 18:05 |
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 #309996 is a reply to message #309994] |
Tue, 14 November 2006 20:33 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.03587 seconds