File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes code throws FileNotFoundException access denied Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "code throws FileNotFoundException access denied" Watch "code throws FileNotFoundException access denied" New topic

code throws FileNotFoundException access denied

Olivia Mayo

Joined: May 11, 2003
Posts: 29
I got this code and tried it out in my servlet but I keep getting a FileNotFoundException and access is denied "dirName". Can someone help?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

The only problem with this code is the "catch" block, which swallows the exception and doesn't log any indicator of where the error happens; for testing, at least, it could log the stack trace.
Anyway, a FileNotFoundException means just that: a file doesn't exist. Figure out why your code thinks a file that does not exist does exist, and you'll have solved the problem.
In a servlet, it's likely that the problem is that you're wrong about where the "current directory" is, and that's the root of the problem. Sounds like your servlet doesn't have write access to the current directory, which is common. The servlet shouldn't try to create files there; it should have its own "scratch directory" to use.
[ July 18, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: code throws FileNotFoundException access denied
It's not a secret anymore!