Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » IFile to java.io.File
IFile to java.io.File [message #290664] Mon, 29 August 2005 14:41 Go to next message
Eclipse UserFriend
Originally posted by: shane.infotec.com

Hi,

I was wondering if it's possible to convert a
org.eclipse.core.resources.IFile to a java.io.File. I want to parse the
file using javax.xml.parsers.DocumentBuilder, but the method public
Document parse(File f) takes in a java.io.File as a parameter.

Any thoughts?

Shane
Re: IFile to java.io.File [message #290666 is a reply to message #290664] Mon, 29 August 2005 15:03 Go to previous messageGo to next message
Simon Vaillancourt is currently offline Simon VaillancourtFriend
Messages: 4
Registered: July 2009
Junior Member
This should do it.

IFile f = (IFile)element.getUnderlyingResource();
IPath path2 = f.getFullPath();
File file = path2.toFile();


"Shane" <shane@infotec.com> wrote in message
news:02502bec048fe071582c1d1bded0d6eb$1@www.eclipse.org...
> Hi,
>
> I was wondering if it's possible to convert a
> org.eclipse.core.resources.IFile to a java.io.File. I want to parse the
> file using javax.xml.parsers.DocumentBuilder, but the method public
> Document parse(File f) takes in a java.io.File as a parameter.
>
> Any thoughts?
>
> Shane
>
Re: IFile to java.io.File [message #290668 is a reply to message #290666] Mon, 29 August 2005 15:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

OR a simpler way would be:

DocumentBuilder.parse(ifile.getContents());


--
Thanks,
Rich Kulp
Re: IFile to java.io.File [message #291100 is a reply to message #290666] Wed, 07 September 2005 19:50 Go to previous message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

Simon Vaillancourt wrote:
> IFile f = (IFile)element.getUnderlyingResource();
> IPath path2 = f.getFullPath();
> File file = path2.toFile();

This snippet is wrong. The correct way to get a java.io.File from IFile is:

IFile f = ...;
IPath location = f.getLocation();
if (location != null)
java.io.File file = location.toFile()

The "full path" of a resource is not a file system path, but rather a
path in the workspace tree (relative to workspace root).
--
Previous Topic:How to add items to the menu bar.
Next Topic:Supported operating systems in eclipse 3
Goto Forum:
  


Current Time: Thu Apr 25 07:50:26 GMT 2024

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

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

Back to the top