• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to rename file  RSS feed

 
Raghu Devatha
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying an exercise of deleting lines from a file not starting with a particular string. The idea was to copy the desired lines to a temp file, delete the original file and rename the temp file to original file.

Following is what I was trying...




>java -version
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode)
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not closing the output file anywhere. Call wt.close() somewhere in your code, at line 48 for example.

*edit*: Oh, I see you're closing it in line 70. But the file needs to be closed before you delete or rename it; it won't work if the file is open when you try to delete or rename it.
 
Raghu Devatha
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper de Jong.

Mistake from my side.

Thanks again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!