This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,860 Users
  • 2,269,775 Discussions
  • 7,916,823 Comments

Discussions

Problem with FileNotFoundException

803077
803077 Member Posts: 9
edited Mar 17, 2011 11:15AM in Java Desktop Applications
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?

Answers

  • morgalr
    morgalr Member Posts: 457
    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.
  • EJP
    EJP Member Posts: 32,943 Gold Crown
    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.
  • morgalr
    morgalr Member Posts: 457
    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.
This discussion has been closed.