The moose likes I/O and Streams and the fly likes Loading a file from classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Loading a file from classpath" Watch "Loading a file from classpath" New topic
Author

Loading a file from classpath

M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 82
Hi,

I am working on a web application in RAD with websphare server. I have a propoerties file which is in /WEB-INF/classes folder. I am not able to load the file by accessing only through its name. I have to get the absolute path to by using



to get the file. What settings I need to do so I don't have to append the absolute path before file name. I have also tried classpath:filename, but it doesn't work.

Thanks,
Me
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

The usual way to access a file in the classpath is like this:

Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

If you ever need to use absolute file names within a Servlet container, use ServletContext.getRealPath.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 82
Thanks Paul, Its working for me now.

However, just wanted to know if there is any way i can make settings in web.xml or somewhere so my propoerties files are loades by name only or by itself?
 
 
subject: Loading a file from classpath
 
Threads others viewed
Create file object for each assets item.
Accesing image files in java beans
Applet settings in WSAD
FileNotFound
Problem getting applet in WSAD
IntelliJ Java IDE