Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading excel file from relative path

 
Swathi Sri
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you loading the file? Please post the relevant code.
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put the file into WEB-INF/classes/ folder, then you can read it through the following command:

 
Swathi Sri
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you for the reply. Yes, that works. Also, I tried getServletContext().getResource(), which is working.

Regards,
Swathi
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic