Created File Missing in the workspace [message #246096] |
Mon, 21 January 2008 09:44  |
Eclipse User |
|
|
|
Originally posted by: hilal.arslan.bte.mam.gov.tr
I work on Platform pluin development. I'm able to create a new project and
a folder in it as well but I cannot create a healthy file inside that
folder with the following code. The file does appear in the package
explorer view but not in the workspace. And when I try to open the file
from the package explorer it says "Windows cannot find ...\deneme.txt"
IFolder fld;
IFile file1;
IPath ptt;
IPath ptt1;
ptt=newProject.getFullPath();
ptt=ptt.append("/src");
fld = this.createFolderHandle(ptt);
fld.create(true, true, null);
file1=fld.getFile("deneme.txt");
file1.create(null, true, null);
Note: I also tried with a not null InputStream but it did't work
Can you help me with this?
|
|
|
|
Re: Created File Missing in the workspace [message #246207 is a reply to message #246105] |
Mon, 21 January 2008 14:36   |
Eclipse User |
|
|
|
Hi Hilal,
Creating files, folders and any kind of resources in the workspace has
some specific characteristics :) (Hope you will never come to deleting
files).
The workspace can be accessed by every plugin. Each plugin might work in
its own thread. This leads to the need of uniformed access to the
workspace. Especially when creating resource.
So there are generally two ways to create a resource in the workspace.
1. ResourcesPlugin.getWorkspace().run() - synchronous. Just check the
documentation
http://help.eclipse.org/help33/topic/org.eclipse.platform.do c.isv/reference/api/org/eclipse/core/resources/IWorkspace.ht ml#run (org.eclipse.core.resources.IWorkspaceRunnable,%20org.eclips e.core.runtime.jobs.ISchedulingRule,%20int,%20org.eclipse.co re.runtime.IProgressMonitor)
2. Job = new WorkspaceJob(); job.schedule() - asynchronous -
http://www.eclipse.org/articles/Article-Concurrency/jobs-api .html
Using one of this approaches will guarantee to some extend that you are
correctly modifying the workspace. Especially for you case. Are you
using any of this approaches?
Of course as Ed said try using a valid input stream for the creation of
the file.
There are plenty of classes available at org.eclispe.core.filebuffers
and org.eclipse.jface.text that might help you more easily edit text files.
If you are getting strange exceptions or status object that contains
errors it would be much easier if you post more of the code.
Best Regards,
Kiril
Ed Merks wrote:
> Hilal,
>
> It sounds like the file might be marked as not local as a result of this:
>
> * @param source an input stream containing the initial contents of
> the file,
> * or <code>null</code> if the file should be marked as not local
>
> You might need to call refreshLocal for it now...
>
>
> Hilal wrote:
>> I work on Platform pluin development. I'm able to create a new project
>> and a folder in it as well but I cannot create a healthy file inside
>> that folder with the following code. The file does appear in the
>> package explorer view but not in the workspace. And when I try to open
>> the file from the package explorer it says "Windows cannot find
>> ...\deneme.txt"
>>
>> IFolder fld;
>> IFile file1;
>> IPath ptt;
>> IPath ptt1;
>>
>> ptt=newProject.getFullPath();
>> ptt=ptt.append("/src");
>> fld = this.createFolderHandle(ptt);
>> fld.create(true, true, null);
>> file1=fld.getFile("deneme.txt");
>> file1.create(null, true, null);
>>
>>
>> Note: I also tried with a not null InputStream but it did't work Can
>> you help me with this?
>>
|
|
|
|
|
Re: Created File Missing in the workspace [message #246629 is a reply to message #246358] |
Thu, 24 January 2008 02:51  |
Eclipse User |
|
|
|
Hi Hilal,
To create a file you do not need a FileInputStream. You need an
InputStream. Check google on how to create an input stream from a
string. But the steps are - create a ByteArrayOutputStream, write the
content to the output stream, create a ByteArrayInputStream from the
output stream, create the file. If of course that is what you are trying
to do.
I have fight once with a FileNotFoundException for an existing file. Is
the description of the exception something like (The file can not be
found since a user-mapped section is opened)?
Best Regards,
Kiril
Hilal wrote:
> Hi Ed;
> I saw that my file is not local while debugging.
> I did modify the code with refreshLocal() and a non-null
> FileInputStream. I created a new filemanually in "c:\den\dene.txt". And
> called new FileInputStream with that path. But this time it hits
> "FileNotFoundException".
> I'm quite sure about the string format I've entered. So what may be the
> reason for that exception? And is this the only way for creating files?
> I mean shall we create a file manually for non null FileInputStream?
> IFolder fld;
> IFile file1;
> IPath ptt;
> IPath ptt1;
>
> ptt=newProject.getFullPath();
> ptt=ptt.append("/src");
> fld = this.createFolderHandle(ptt);
> fld.create(true, true, null);
> file1=fld.getFile("deneme.txt");
> try {
> source = new FileInputStream("c:/den/dene.txt");//////NEWLY ADDED///
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace(); ////////////HITS HERE...EXCEPTION///
> }
> file1.create(null, true, null);
> file1.create(source, IResource.FORCE, null);//////////NEWLY ADDED////////
> file1.refreshLocal(IResource.DEPTH_ZERO, null);
>
|
|
|
Powered by
FUDForum. Page generated in 0.08621 seconds