• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to specify the Relative path of a file in fileinputstream?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to mention the relative path of the file in fileinputstream?

The directory structure is as follows,Inside the **model** folder i have a java file called GetContents.java
I need to refer the input.xls( a file inside the template folder ) in GetContents.java file.

I tried

new FileInputStream("..\\..\\..\\template\\DevContentsTemplate.xls")


cos the GetContents.class file will be inside webcontent\web-inf\classes\model\GetContents.class and I thought if i use the above relative path , it should refer webcontent\web-inf\template\input.xls
But it throws a file not found exception.

Please note that i have configured the tomcat server working directory to point to my current project "CVT"

Kindly help.

Thanks.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You specified three directories up, which takes you out of the WEB-INF folder.

Also, you may want to use ServletContext's getRealPath method combined with the absolute path (from the web application folder):
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic