3 Replies Latest reply: Mar 17, 2011 10:15 AM by morgalr RSS

    Problem with FileNotFoundException

    803077
      Hi. Sometimes in my application i have problems with FileNotFoundException, but file which i want to open exists. In the documentation I found that:"It will also be thrown by these constructors if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing." What can be another reason that the file is inaccessible?
        • 1. Re: Problem with FileNotFoundException
          morgalr
          File can be corrupt, it can be locked by another application, the windows system is blocking your access for a host of reasons--the least of which is that something else has used it in the past few minutes and windows thinks it is still in use.
          • 2. Re: Problem with FileNotFoundException
            EJP
            File can be corrupt
            That will not throw a FileNotFoundException.
            it can be locked by another application
            That will throw a FileNotFoundException
            the windows system is blocking your access for a host of reasons
            That's the general case of the previous special case.
            the least of which is that something else has used it in the past few minutes and windows thinks it is still in use.
            That doesn't happen unless the file is currently in use, which you have already covered above.
            • 3. Re: Problem with FileNotFoundException
              morgalr
              EJP wrote:
              That doesn't happen unless the file is currently in use ...
              I would have to dissagree with you there. Not frequently, but on occasioin, I have had windows just not release a lock that is has on a file. I've had this happen with various editors--Word and Notepad are ones that recently come to mind. It has also happened to me doing a copy from one folder to another. Windows Media Player has also expressed a problem and also Excel and Access. I have had these problems in Windows 7, XP, and other previous Windows versions. And please do not think this is limited to accessing a file with Java--it has expressed in various MS development tools and even just using MS products--no programming outside of the shrink wrap MS product was used.