aspose file tools*
The moose likes Servlets and the fly likes java.io.FileNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "java.io.FileNotFoundException" Watch "java.io.FileNotFoundException" New topic
Author

java.io.FileNotFoundException

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
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

Joined: Mar 22, 2000
Posts: 12835
    
    5
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Thank you very much,
The getRealPath() has fixed the problem.
 
wood burning stoves
 
subject: java.io.FileNotFoundException