• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing an Excel file inside a WAR file  RSS feed

 
Sam Seagal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I saw a post with the exact question I have, but I couldn�t find the answer. So I�l post it again, hope someone can help me.

I have an Excel file that I packaged with my WAR file, which I am using
as a template for a certain download. When the user clicks a button, this file is read and it's content is saved as a downloaded file. The thing is, I am having problems accessing the Excel file. It seems like I cannot read the file inside the WAR. I tried accessing the same file, now saved in a directory outside of my WAR file, and the file is downloaded correctly. Does anybody out there knows how to correctly access a file inside a WAR file?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You should be able to get hold of an InputStream for the file through the servlet context's getResourceAsStream(String) method.

By the way, is "sebasrf" really a proper first name? If not, then please fix it to something valid according to the JavaRanch naming policy.
 
Sam Seagal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I have fix the problem with this code:

//load the properties file
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(TEMPLATE_PATH);

//Sets template as a POIFSFileSystem.
POIFSFileSystem fs = new POIFSFileSystem (inputStream);

//Closes input stream
inputStream.close();

//Load input file with templates and create the WorkBook object with templates of input file
HSSFWorkbook objWB = new HSSFWorkbook (fs);

Thanks for the help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!