referring to a java class in Eclipse folders

T

TFM

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.
 
A

Andrew Thompson

TFM said:
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.
 
T

Thomas Fritsch

TFM said:
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.
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 '/'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top