File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Reading excel file from relative path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Reading excel file from relative path" Watch "Reading excel file from relative path" New topic
Author

Reading excel file from relative path

Swathi Sri
Greenhorn

Joined: Jan 18, 2007
Posts: 22
Hi,

I am trying to read an excel file. It is existing under web-inf folder. I am calling this file from helper/dao class. How should I give path? I tried \\context-path\\excel-file-name. It is giving File not found exception.

I have also tried copying excel file to the folder where the helper/dao class is existing and by using just excel-file-name in the file path. It did not work either.

Can anybody please suggest a way to read this file?

Thanks,
Swathi
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10069
    
163

How are you loading the file? Please post the relevant code.


[My Blog] [JavaRanch Journal]
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
You can put the file into WEB-INF/classes/ folder, then you can read it through the following command:



Regards, Jair Rillo Junior
http://www.jairrillo.com/blog, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
Swathi Sri
Greenhorn

Joined: Jan 18, 2007
Posts: 22
Hi,
Thank you for the reply. Yes, that works. Also, I tried getServletContext().getResource(), which is working.

Regards,
Swathi
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
Originally posted by Swathi Sri:
Hi,
Thank you for the reply. Yes, that works. Also, I tried getServletContext().getResource(), which is working.

Regards,
Swathi


Be careful with getServletContext().getResource(). As far as I know, it doesn't work when your application is packaged in a .WAR file.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Reading excel file from relative path