• Post Reply Bookmark Topic Watch Topic
  • New Topic

Debugging: File deletion failed

 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I've been having quite a bit of trouble with this one and I really can't figure out what the problem is. I have a method that opens an existing file, preferences.txt and then opens a second file, temp.txt, temp is used as a holder to modify preferences. Once everything is written to temp, preferences is deleted and temp is renamed to preferences. Here's the relevant code segment:



Here's what I've checked so far:
- I can read/write to that directory
- The file does exist
- I've checked, checked and checked again and I see no objects using this file that were not closed appropriately

How do you guys debug this kind of stuff? The method will work sporadically (or what seems like sporadically) and I can't seem to track down a rhyme or reason to it working vs. not working.

Thanks for any help guys!
 
Rishi Shah
Ranch Hand
Posts: 43
Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Java 7? If you are, use the new File IO introduced in Java7 (http://docs.oracle.com/javase/tutorial/essential/io/fileio.html)

Also, there's no need to write to a temp file, simply overwrite the original preferences file.
 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rishi Shah wrote:Are you using Java 7? If you are, use the new File IO introduced in Java7 (http://docs.oracle.com/javase/tutorial/essential/io/fileio.html)

Also, there's no need to write to a temp file, simply overwrite the original preferences file.


Thanks Rishi - I'll give that a shot and see if that helps
 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rishi - that seems to have improved response, but I'm still getting the occasional problem - it throws a FileSystemException occasionally. I'm starting to think that maybe this is just Windows doing what Windows does...does that sound right?

Is there anyway to manually close all instances on a particular file?


EDIT: Scratch that - I had a second instance of the program running in Netbeans and that appeared to be causing the error. Thanks so much Rishi - this was driving me up the wall!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!