File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes code not deleting txt file and renaming new txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "code not deleting txt file and renaming new txt file " Watch "code not deleting txt file and renaming new txt file " New topic
Author

code not deleting txt file and renaming new txt file

George Avilez
Ranch Hand

Joined: Apr 26, 2013
Posts: 60
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

Joined: Apr 26, 2013
Posts: 60
Here is line counter if the problem might be here...

Krishna Kanth
Ranch Hand

Joined: Oct 23, 2006
Posts: 49
    
    1

Probably becuase inputStream is not closed in viewList method?
Krishna Kanth
Ranch Hand

Joined: Oct 23, 2006
Posts: 49
    
    1

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

Joined: Apr 26, 2013
Posts: 60
Thank you very much man!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code not deleting txt file and renaming new txt file
 
Similar Threads
How to end this loop
Boolean for deleting txt file and renaming new txt file not working
Creating a proper if/else statement for this txt input
Unable to rename file
Trying to delete a string from a text file