Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

referring to a java class in Eclipse folders

Thread view: 
TFM - 30 Aug 2006 10:01 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.

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.