Unable to access Java-created file -- sometimes

Posted by BlairHippo on Stack Overflow See other posts from Stack Overflow or by BlairHippo
Published on 2010-04-13T15:19:30Z Indexed on 2010/04/13 15:23 UTC
Read the original article Hit count: 311

Filed under:
|
|

In Java, I'm working with code running under WinXP that creates a file like this:


   public synchronized void store(Properties props, byte[] data) {
      try {
         File file = filenameBasedOnProperties(props);
         if ( file.exists() ) {
            return;
         }         
         File temp = File.createTempFile("tempfile", null);
         FileOutputStream out = new FileOutputStream(temp);
         out.write(data);
         out.flush();
         out.close();
         file.getParentFile().mkdirs();
         temp.renameTo(file);
      } 
      catch (IOException ex) {
         // Complain and whine and stuff
      }
   }

Sometimes, when a file is created this way, it's just about totally inaccessible from outside the code (though the code responsible for opening and reading the file has no problem), even when the application isn't running. When accessed via Windows Explorer, I can't move, rename, delete, or even open the file. Under Cygwin, I get the following when I ls -l the directory:

ls: cannot access [big-honkin-filename]
total 0
?????????? ? ? ? ?            ? [big-honkin-filename]

As implied, the filenames are big, but under the 260-character max for XP (though they are slightly over 200 characters).

To further add to the sense the my computer just wants me to feel stupid, sometimes the files created by this code are perfectly normal. The only pattern I've spotted is that once one file in the directory "locks", the rest are screwed.

Anybody ever run into something like this before, or have any insights into what's going on here?

© Stack Overflow or respective owner

Related posts about java

Related posts about windows-xp