Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Working with files? Is it so different from java.io?
Working with files? Is it so different from java.io? [message #301100] Thu, 23 March 2006 14:10 Go to next message
Eclipse UserFriend
Hi all,

I am finding the concept of files within Eclipse a bit confusing compared
to java.io. It would be helpful if someone could point out the differences.
I would also like to ask a couple of questions.

1/ Is it correct that you can not create a File that doesn't exist like you
can with java.io?

2/ I wish to create a file outside the workspace how do I do this? I have
looked at the code for the export wizard ... there must be an easier way to
do it with perhaps a few lines of code!

thanks for any help


Martin
Re: Working with files? Is it so different from java.io? [message #301101 is a reply to message #301100] Thu, 23 March 2006 14:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: matt.querix.com

Hi Martin,

> 1/ Is it correct that you can not create a File that doesn't exist like you
> can with java.io?

You can create create an IFile object for any path within the workspace.
It must have at least two segments. Also note that while java.io.File
can represent a file or a directory, Eclipse uses IWorkspaceRoot for the
root of the workspace, IProject (which corresponds to a directory) for
projects in your Eclipse workspace, IFolder for directories and IFile
for files only. These have a common superclass, IResource.

>
> 2/ I wish to create a file outside the workspace how do I do this? I have
> looked at the code for the export wizard ... there must be an easier way to
> do it with perhaps a few lines of code!

It is best to use IFile, IFolder, etc for resources in the workspace
root, so that the Eclipse platform knows about the changes you make to
them and can show them to the user. But you cannot use these for files
outside of the workspace, so just use java.io.File.

>
> thanks for any help
>
>
> Martin
>
>
>
>
Re: Working with files? Is it so different from java.io? [message #301102 is a reply to message #301101] Thu, 23 March 2006 14:29 Go to previous messageGo to next message
Eclipse UserFriend
thanks for the reply Matt,

but how do I create an IFile from a java.io.File that still represents the
file outside the workspace?

thanks


"Matt Dickie" <matt@querix.com> wrote in message
news:dvusi0$dp0$1@utils.eclipse.org...
> Hi Martin,
>
> > 1/ Is it correct that you can not create a File that doesn't exist like
you
> > can with java.io?
>
> You can create create an IFile object for any path within the workspace.
> It must have at least two segments. Also note that while java.io.File
> can represent a file or a directory, Eclipse uses IWorkspaceRoot for the
> root of the workspace, IProject (which corresponds to a directory) for
> projects in your Eclipse workspace, IFolder for directories and IFile
> for files only. These have a common superclass, IResource.
>
> >
> > 2/ I wish to create a file outside the workspace how do I do this? I
have
> > looked at the code for the export wizard ... there must be an easier way
to
> > do it with perhaps a few lines of code!
>
> It is best to use IFile, IFolder, etc for resources in the workspace
> root, so that the Eclipse platform knows about the changes you make to
> them and can show them to the user. But you cannot use these for files
> outside of the workspace, so just use java.io.File.
>
> >
> > thanks for any help
> >
> >
> > Martin
> >
> >
> >
> >
Re: Working with files? Is it so different from java.io? [message #301114 is a reply to message #301102] Thu, 23 March 2006 17:19 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Basically you can't. IFile is only for files within the workspace. The
only way it can be "outside" the workspace is if it is in a folder (or
some parent folder of the file) that is linked into a project as a
folder that is not inside a project. Linked means the project knows
about and can manage the folder. It implicitly knows how to do this for
files that are directly under the project or a folder under the project.

--
Thanks,
Rich Kulp
Previous Topic:Document Provider Question
Next Topic:how to RELIABLY open a MessageDialog from progress monitor run method
Goto Forum:
  


Current Time: Thu Sep 18 17:23:28 EDT 2025

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

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

Back to the top