Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.FileNotFoundException

 
Azz Romaysa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trting to send an attachment file using javaMail. My problem is if I set the whole path of the file (for example: C:/myFile.jsp), then it works. But not if I set a relative path.

This is the code:
Mailer.java



Ans I call this method from my servlet
OfferController.java


The exception that I get:
java.io.FileNotFoundException: \vrijblijvend_offerte.jsp (The system cannot find the path specified)

My structure:
|
|-WEB-INF
|-vrijblijvend_offerte.jsp
|

Thank you,
Abu
[ October 22, 2005: Message edited by: Azz Romaysa ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You "relative" file path usage depends on the "current" directory - something you can't control in a servlet. You can convert a relative path in a servlet context to an absolute path - see the ServletContext getRealPath method.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two methods you should read up on:
getRealPath and getResourceAsStream.

Both are methods of ServletContext
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html


Note: getRealPath has a serious drawback. If you're running your application from a packed war file getRealPath will return null.
 
Azz Romaysa
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much,
The getRealPath() has fixed the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic