Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to create file in the workspace?
How to create file in the workspace? [message #296300] Tue, 20 December 2005 05:35 Go to next message
Eclipse UserFriend
Originally posted by: address.starts.after.hyphen-martin.umgeher.joanneum.at

I have troubles creating files in a folder of a workspace project.
Here's what I do:

assert project.exists() && project.isOpen();
IFolder folder = project.getFolder("myfolder");
assert folder.exists();
IFile file = folder.getFile("myfile");
assert !file.exists();
file.create(stream, false, monitor);
assert file.exists();

IFile.create fails with a ResourceException telling me that:

"Resource /myproject/myfolder already exists."

So #create fails because the target folder exists, but I intended to
create a file in there... any hints what I'm doing wrong?

Thanks,
M
Re: How to create file in the workspace? [message #296302 is a reply to message #296300] Tue, 20 December 2005 06:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

You could always try specifying the 'force' flag to force it to create the file.

It's also possible that you've just created the IFolder from previous uses, and because the actual creation happens in a WorkspaceRunnable, that it hasn't fully commited the changes whilst the thread running. That's the only thing that I can think of, though.

Alex.
Re: How to create file in the workspace? [message #296304 is a reply to message #296302] Tue, 20 December 2005 07:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: address.starts.after.hyphen-martin.umgeher.joanneum.at

Alex Blewitt wrote:
> You could always try specifying the 'force' flag to force it to create the file.
>
> It's also possible that you've just created the IFolder from previous uses, and because the actual creation happens in a WorkspaceRunnable, that it hasn't fully commited the changes whilst the thread running. That's the only thing that I can think of, though.

Hi!

Thanks for your answer. I tried to set the 'force' flag to true, but
#create still fails with the same exception. The second potential issue
doesn't apply either because both project and folder were created in a
previous run of the application.

Any other ideas?

M
Re: How to create file in the workspace? [message #296313 is a reply to message #296304] Tue, 20 December 2005 08:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: address.starts.after.hyphen-martin.umgeher.joanneum.at

martin wrote:
> Alex Blewitt wrote:
>
>> You could always try specifying the 'force' flag to force it to create
>> the file.
>>
>> It's also possible that you've just created the IFolder from previous
>> uses, and because the actual creation happens in a WorkspaceRunnable,
>> that it hasn't fully commited the changes whilst the thread running.
>> That's the only thing that I can think of, though.
>
>
> Hi!
>
> Thanks for your answer. I tried to set the 'force' flag to true, but
> #create still fails with the same exception. The second potential issue
> doesn't apply either because both project and folder were created in a
> previous run of the application.
>
> Any other ideas?
>
> M

Ok, got it now. Problem was that the string passed to IFolder.getFile
was empty. The error message is quite confusing imho...

M
Re: How to create file in the workspace? [message #296315 is a reply to message #296304] Tue, 20 December 2005 09:00 Go to previous message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

They can be caused because they're out of sync with the file system. Try doing a folder.refreshLocal(IResource.DEPTH_ONE,null) first of all (or even project.refreshLocal(IResource.DEPTH_ONE,null)) to check that the state of the workspace is up to date with the folder location. It may be that the file exists on disk, but that the workspace doesn't know about it yet.

Alex.
Previous Topic:Eclipse 3.2 M4 plugin resolution problems under Java 1.6
Next Topic:using the internal tomcat plugin
Goto Forum:
  


Current Time: Thu Oct 30 19:35:13 EDT 2025

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

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

Back to the top