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 / June 2007

Tip: Looking for answers? Try searching our database.

Locating a file on the disk using ClassLoader

Thread view: 
ramiab3@gmail.com - 11 Jun 2007 07:10 GMT
Hello all,

How one finds a file on the disk using the ClassLoader?

It is not necessarily a java class, and using an absolute path is not
an option since it can reside under different roots.
What is certain is the file's name and its relative path to the
ClassLoader.

thank you,

Rami
Thomas Fritsch - 11 Jun 2007 12:22 GMT
ramiab3@gmail.com schrieb:
> How one finds a file on the disk using the ClassLoader?
>
> It is not necessarily a java class, and using an absolute path is not
> an option since it can reside under different roots.
> What is certain is the file's name and its relative path to the
> ClassLoader.
ClassLoader has 2 methods for your purpose:
  public URL getResource(String name)
  public InputStream getResourceAsStream(String name)
See <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html>

Signature

Thomas

Lew - 11 Jun 2007 12:28 GMT
> ramiab3@gmail.com schrieb:
>> How one finds a file on the disk using the ClassLoader?
[quoted text clipped - 7 lines]
>   public InputStream getResourceAsStream(String name)
> See <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html>

In general when one has a question about a particular class or package in the
standard API one should refer to the API docs.

Signature

Lew

Arne Vajhøj - 12 Jun 2007 02:18 GMT
> How one finds a file on the disk using the ClassLoader?
>
> It is not necessarily a java class, and using an absolute path is not
> an option since it can reside under different roots.
> What is certain is the file's name and its relative path to the
> ClassLoader.

Do you need to read the content of the file or do you need to
find the absolute path of the file ?

Arne
cyprian - 12 Jun 2007 11:02 GMT
On Jun 12, 2:18 am, Arne Vajh?j <a...@vajhoej.dk> wrote:
> rami...@gmail.com wrote:
> > How one finds a file on the disk using the ClassLoader?
[quoted text clipped - 8 lines]
>
> Arne

where's the API?
Arne Vajhøj - 13 Jun 2007 03:25 GMT
>> rami...@gmail.com wrote:
>>> How one finds a file on the disk using the ClassLoader?
[quoted text clipped - 5 lines]
>> find the absolute path of the file ?
> where's the API?

If you have a new question I recommend you create a new thread.

Arne


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



©2009 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.