Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Using workspace in RCP Application - Part 2
Using workspace in RCP Application - Part 2 [message #453345] Thu, 27 July 2006 01:19 Go to next message
Eclipse UserFriend
Originally posted by: baldin.gmail.com

Hello again,

Stan, thanks if you help me again.

With teh last post, i got the Workspace root directory. But learning more
from IWorkspace, IWorkspaceRoot, i got this:

Workspace
-> Project
-> File
->Folder
->File
->Folder
-> [...]

But i want to save files and folder directly in WorkspaceRoot. I need to
respect hierarchy creating project and open before, or can do it ?

Geting the WorkspaceRoot.toString() path i can save and read file without
IResource interface, just using in the File name, but a think this is no
good idea......

I try this code, but i get Exception:

<<<<<<<<<<<<<<console exit
F:/runtime-EclipseApplication/servers.xml
servers.xml
error creating file
org.eclipse.core.internal.resources.ResourceException: Resource
/runtime-EclipseApplication does not exist.
at
org.eclipse.core.internal.resources.Resource.checkExists(Res ource.java:311)
at
org.eclipse.core.internal.resources.Resource.checkAccessible (Resource.java:187)
at
org.eclipse.core.internal.resources.Project.checkAccessible( Project.java:142)
[...]

the code

public static void createWorkspaceFile(String pathName, InputStream source)
{
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IFile file = root.getFile(root.getLocation().append(pathName));
System.out.println(root.getLocation().append(pathName).toPor tableString());
System.out.println(file.getName());
file.create(source, IResource.FORCE, null); //this raise
ResourceException
}catch (Exception e) {
System.out.println("error creatin file");
e.printStackTrace();
}
}

the use

LocalResources.createWorkspaceFile("servers.xml", new
ByteArrayInputStream("hello word".getBytes()));

Allot thanks,

Regards,

Davi !
Re: Using workspace in RCP Application - Part 2 [message #453385 is a reply to message #453345] Fri, 28 July 2006 00:39 Go to previous message
Eclipse UserFriend
Originally posted by: zzhang.numericatech.com

Hi, David,

I am not sure if you can directly create files under Workspace root. I think
all the files must be under some project..

This might help you...

http://wiki.eclipse.org/index.php/FAQ_How_do_I_open_an_edito r_on_a_file_outside_the_workspace%3F


Sincerely,
Stan

"Davi Baldin" <baldin@gmail.com> wrote in message
news:ea94bn$ldk$1@utils.eclipse.org...
> Hello again,
>
> Stan, thanks if you help me again.
>
> With teh last post, i got the Workspace root directory. But learning more
> from IWorkspace, IWorkspaceRoot, i got this:
>
> Workspace
> -> Project
> -> File
> ->Folder
> ->File
> ->Folder
> -> [...]
>
> But i want to save files and folder directly in WorkspaceRoot. I need to
> respect hierarchy creating project and open before, or can do it ?
>
> Geting the WorkspaceRoot.toString() path i can save and read file without
> IResource interface, just using in the File name, but a think this is no
> good idea......
>
> I try this code, but i get Exception:
>
> <<<<<<<<<<<<<<console exit
> F:/runtime-EclipseApplication/servers.xml
> servers.xml
> error creating file
> org.eclipse.core.internal.resources.ResourceException: Resource
> /runtime-EclipseApplication does not exist.
> at
> org.eclipse.core.internal.resources.Resource.checkExists(Res ource.java:311)
> at
> org.eclipse.core.internal.resources.Resource.checkAccessible (Resource.java:187)
> at
> org.eclipse.core.internal.resources.Project.checkAccessible( Project.java:142)
> [...]
>
> the code
>
> public static void createWorkspaceFile(String pathName, InputStream
> source) {
> try {
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
> IWorkspaceRoot root = workspace.getRoot();
> IFile file = root.getFile(root.getLocation().append(pathName));
>
> System.out.println(root.getLocation().append(pathName).toPor tableString());
> System.out.println(file.getName());
> file.create(source, IResource.FORCE, null); //this raise
> ResourceException
> }catch (Exception e) {
> System.out.println("error creatin file");
> e.printStackTrace();
> }
> }
>
> the use
>
> LocalResources.createWorkspaceFile("servers.xml", new
> ByteArrayInputStream("hello word".getBytes()));
>
> Allot thanks,
>
> Regards,
>
> Davi !
>
Previous Topic:perspective createInitialLayout never called
Next Topic:Class for Managing Events
Goto Forum:
  


Current Time: Sat Oct 05 13:03:26 GMT 2024

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

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

Back to the top