Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » IFile to String and back to IFile
IFile to String and back to IFile [message #326582] Tue, 25 March 2008 17:34 Go to next message
Eclipse UserFriend
Originally posted by: dan.edmunds.ca.gmail.com

Hi All,

I'm willing to bet someone else has already asked this question but I'm
having trouble searching through the message board posts. Sorry!

I'm trying to save an IFile to String and later use that String to get
back to the IFile. I have a reference to the containing project if that
helps.

I'm generating the string in the following way:
IFile file ...
String toSave = file.getFullPath().toString();

I've tried the following two ways to get back to the IFile...
IProject project ... //container project
String filePath ... //the String generated previously

//1, gives me null
Path path = new Path(filePath);
IFile file = root.getFileForLocation(path);

//2, also give me null
IResource resource = project.findMember(path);
if(resource != null && resource.getType() == IResource.FILE)
IFile file = (IFile)resource;

Any help would be greatly appreciated, again sorry for the likely double
post.

-Dan
Re: IFile to String and back to IFile [message #326585 is a reply to message #326582] Tue, 25 March 2008 18:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Dan,

The full path includes the project name. You'd want to use the full path
from the IWorkspaceRoot.


Dan wrote:
> Hi All,
>
> I'm willing to bet someone else has already asked this question but
> I'm having trouble searching through the message board posts. Sorry!
>
> I'm trying to save an IFile to String and later use that String to get
> back to the IFile. I have a reference to the containing project if
> that helps.
>
> I'm generating the string in the following way:
> IFile file ...
> String toSave = file.getFullPath().toString();
>
> I've tried the following two ways to get back to the IFile...
> IProject project ... //container project
> String filePath ... //the String generated previously
>
> //1, gives me null
> Path path = new Path(filePath);
> IFile file = root.getFileForLocation(path);
>
> //2, also give me null
> IResource resource = project.findMember(path);
> if(resource != null && resource.getType() == IResource.FILE)
> IFile file = (IFile)resource;
>
> Any help would be greatly appreciated, again sorry for the likely
> double post.
>
> -Dan
>
>
Re: IFile to String and back to IFile [message #326600 is a reply to message #326582] Wed, 26 March 2008 08:32 Go to previous message
Eclipse UserFriend
Originally posted by: valere.fedronic.ext.streamezzo.com

Hi,
Take a look at the ResourceFactory (org.eclipse.ui.ide).

Valère.


Dan a écrit :
> Hi All,
>
> I'm willing to bet someone else has already asked this question but I'm
> having trouble searching through the message board posts. Sorry!
>
> I'm trying to save an IFile to String and later use that String to get
> back to the IFile. I have a reference to the containing project if that
> helps.
>
> I'm generating the string in the following way:
> IFile file ...
> String toSave = file.getFullPath().toString();
>
> I've tried the following two ways to get back to the IFile...
> IProject project ... //container project
> String filePath ... //the String generated previously
>
> //1, gives me null
> Path path = new Path(filePath);
> IFile file = root.getFileForLocation(path);
>
> //2, also give me null
> IResource resource = project.findMember(path);
> if(resource != null && resource.getType() == IResource.FILE)
> IFile file = (IFile)resource;
>
> Any help would be greatly appreciated, again sorry for the likely double
> post.
>
> -Dan
>
>
Previous Topic:Can two Eclipse installations coexist on a hard disc?
Next Topic:What is a content type??
Goto Forum:
  


Current Time: Thu Jun 27 19:54:42 GMT 2024

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

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

Back to the top