IFile to String and back to IFile [message #326582] |
Tue, 25 March 2008 17:34 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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 Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03268 seconds