In my eclipse project, I have a hierarchy of folders (the folders which
you create by doing New->Folder)
I want to refer to a file deep down the folder hiearchy inside a code,
how can I do that.
e.g. there is a file inside
idl/org/openoffice/helloworld/Helloworld.idl
I want to refer to Helloworld.idl from inside a code.
Andrew Thompson - 30 Aug 2006 10:14 GMT
> In my eclipse project, I have a hierarchy of folders (the folders which
> you create by doing New->Folder)
>
> I want to refer to a file deep down the folder hiearchy inside a code,
> how can I do that.
To access resources in Java, place the resource on
the runtime 'classpath'.
> e.g. there is a file inside
> idl/org/openoffice/helloworld/Helloworld.idl
>
> I want to refer to Helloworld.idl from inside a code.
Then you can get an URL to the resaource by using
Class.getResource().
In Eclipse, look for ..
Project Properties | Java Build Path | Source
..then add the folder that contains the (assuming unzipped)
resource of interest.
As an aside, you will get yourself in no end of trouble if
you attempt to use an IDE without understanding how
the underlying Java tools and JVM work. I recommend you
put aside the IDE for the moment and figure how to do this
stuff from the command line.
Andrew T.
Thomas Fritsch - 30 Aug 2006 10:25 GMT
TFM schrieb:
> In my eclipse project, I have a hierarchy of folders (the folders which
> you create by doing New->Folder)
[quoted text clipped - 6 lines]
>
> I want to refer to Helloworld.idl from inside a code.
Sounds as if you want to load this file via the ClassLoader.
Look at the API docs of
Class#getResource.
Class#getResourceAsStream
ClassLoader#getResource
ClassLoader#getResourceAsStream
You can use it like
InputStream stream =
getClass().getResourceAsStream("/idl/org/openoffice/helloworld/Helloworld.idl");
Don't forget the leading '/'.

Signature
Thomas