Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashtable IO  RSS feed

 
eric manget
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, when I click the regi button in my code the keys/values are written to a text file but the text written to the txt file is sometimes the same as the text written before (even when I start the program up again). Help please.


 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric, welcome to Java Ranch!

Your first problem is you open the output file in append mode (line 192), which doesn't make sense if you're going to iterate through the whole hash table. The only way that makes sense if you were just going to add the new values the user just entered.

The second problem is you close the output file in your first iteration through the hash table. That means you will append the first key/value pair of the hash into your file, then won't be able to write anything else to it.

The combination of the two problems means it looks like everything works if the new key and value, by blind luck, just happen to be the first row in the hash table. Otherwise, you'll get a duplication of one of the key/value pairs already in your file.
 
eric manget
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you know that your my best friend for the next 30 minutes while I finish off my login classes?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!