• Post Reply Bookmark Topic Watch Topic
  • New Topic

File rename/delete  RSS feed

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been successful in having a File renamed, but the problem is it leaves the File with the original name behind with 0 bytes, by the way. So I employed the delete() method you see at the end of the method code below and it does not delete the old File. I have heard alot of people have trouble using this method. I have tried placing it in different spots and it never works.

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for anyone wanting to know of a solution in this particualr case, after some more research on the Internet I found this:



just before the delete() method and it works. The old File has been deleted leaving the renamed File with bytes intact.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most common problem with rename and delete is that people don't close streams and readers that are open on the original file. You don't show us what all you are doing with your files, but the fact that you perform a reaname then open a BufferedWriter for writing on the old file (which would create a 0 length file) tells me that the problem is probably in your code.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!