• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code not deleting txt file and renaming new txt file

 
George Avilez
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the user chooses the viewList method (lines 73-84) and then presses deleteItem method right after (lines 1-71), the error at line 45 happens, stating what it says on that line. If the user never touches the view choice then the code will work perfectly fine and the user can keep on deleting items and keep entering invalid items all day. It isn't until the user presses the view choice, then that deleteItem method is just worthless and all they can really do next is create a new list or exit the program. can anybody help? I believe it has to do with the boolean because the new temp file shows the list with the deleted item, it's just not renaming the new temp file and deleting the old one so obviously the deleting item part is working bu not the boolean

 
George Avilez
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is line counter if the problem might be here...

 
Krishna Kanth
Ranch Hand
Posts: 49
1
Chrome Java Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably becuase inputStream is not closed in viewList method?
 
Krishna Kanth
Ranch Hand
Posts: 49
1
Chrome Java Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not closing input stream after reading in viewList is indeed the problem. I just ran with a main method, mocking out scanner etc.

After adding inputStream.close(); on line#101, deleteItem worked after viewList also.

Basically tells me this is a standard windows issue, when a file is open in a different program renaming is not allowed
 
George Avilez
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much man!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic