File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes file access problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "file access problem" Watch "file access problem" New topic
Author

file access problem

Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
Hi all ,
I have been implementing a small code which will access some files within the same context. Currently I have a servlet and implemented as follow to access the files.



I got the file not found exception when the app is run. "variations.uni" file is placed in the root of the app .My dir structure is as follow



please help me solve this problem.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

The context path is a concept for URLs, not file paths.

What are you really trying to do? Where do you want the file to be?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
Bear Bibeault wrote:The context path is a concept for URLs, not file paths.



Oh yes,I just want to read/write the file in the root of app .

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Investigate ServletContext.getRealPath()
Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
thanks so much , bear. I havent accessed files with Stream in web environment before and didnt know that method exists. You help me a lot.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

OK, just be aware that writing into your web app is not generally considered a great thing to do. It can make redeployment and updates a pain.
 
Consider Paul's rocket mass heater.
 
subject: file access problem