cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in java.io.file reading

Former Member
0 Kudos

Hi

I have a servlet and it calls some classes which are kept in a jar file in WEB-INF/lib directory. With in one of the classes there is a IO file read happening. How should i read the file and what path should i put if the file is in WEB-INF/resources

my jar files are in web-inf/lib directory. How will i read the file and what should be the patch to be given

regards,

Sujesh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Check this out

FileInputStream fis = new FileInputStream(new File("..
resources
filenmae"));

.. refers to parent directory ( in your case it is WEB-INF ).

Regards,

Uma

Former Member
0 Kudos

Thanks Uma..

The class reading the file in in some directory structure but lies in a jar file in lib directory

Former Member
0 Kudos

I have a servlet which calls a class. The class inturn reads an xml file which is kept inside web-inf, inside web-inf/lib, and the class's folder. Iam trying to read the file using

InputStream isStream = this.getClass().getClassLoader().getResourseAsStream("config.xml")

isStream is coming as null...how will i read it.I made ear file and deployed in was 6.4 sp11

Any suggestions??

Former Member
0 Kudos

Hi Sujesh,

Can you try the following method..

InputStream inp = this.getClass().getClassLoader().getResourceAsStream("com/package1/abc.xml");

Regards,

Ananth

Answers (1)

Answers (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Sujesh,

you can use getResource(path) or getResourceAsStream, see http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html

See http://www.slamb.org/projects/axamol/sql-library/manual/ch01s03.html for an example.

Hope it helps

Detlev