• Post Reply Bookmark Topic Watch Topic
  • New Topic

file delete and reuse  RSS feed

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to do: overwrite the existing test.txt file each time this runs:


I get no errors, but it refuses to overwrite the file with new data.
Does a file only get to be written to with one filewriter?

I tried deleting the file with testFile.delete() earlier in the code, but it refused to delete the file. Any insight into why it wouldn't delete the file would be great.... and why it reported that the file was deleted when it really wasn't...

Tim
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after reading the docs more closely, I see that the delete() method

"Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates."


this explains why it won't get deleted, but how to overwrite?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I see that the default behavior is to overwrite an existing file. When I moved my file to something like C:\testFile.txt, I saw that default behavior. It must be something particular to my IDE that the src/ directory has different behavior.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!