• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

FileNotFoundException on specifying the relative path.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am having an action class and inside my action class i want to refer to an excel file in the following directory : webContent/WEB-INF/templates/sample.xls.

I am able to access this file if i specify absolute path, but when i give relative path, it gives a FileNotFoundException.

How do i solve this?

Thanks.
 
lr Kiko
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried 2 approaches

1) i tried to use the following in my action class,
String strPath = request.getSession().getServletContext().getRealPath("");

Following is the value set in strPath
C:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ContentValidation

then i tried ,
String strPath = request.getSession().getServletContext().getRealPath("")+"\\WebContent\\WEB-INF\\template\\initial.xls";

Following is the value set in strPath
C:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ContentValidation\WebContent\WEB-INF\template\initial.xls

It says file not found exception.
'But when i use the aboslute path ,
C:\workspace\ContentValidation\WebContent\WEB-INF\template\input.xls
it works fine

2)
String path = request.getContextPath();
System.out.println(path+"/WebContent/WEB-INF/template/input.xls");
output was
/ContentValidation/WebContent/WEB-INF/template/input.xls

but still i get file not found exception

can someone help please

 
I am going to test your electrical conductivity with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic