• Post Reply Bookmark Topic Watch Topic
  • New Topic

Files  RSS feed

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am implementing address book like yahoo. I saw yahoo is allowing to create same name multiple times.
eg. Let's say I create Angela D'souza username with address angela@javaranch.com. This will save. Now again If create another one with username Angela D'souza with angela@javaranch.com It doesn't overwrite old rather creating new entry. How can I do this? If this above senario happend, in my project it will overwrite the old. I am storing address in file. (File name will be username)
Thanks,
Angela
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't sound like an I/O problem, but instead the way your are actually implementing the storage of the name/address pairs. You'll have to give a bit more information on that before someone can help you.
Are you using an ArrayList, a HashMap? If you are just reading and writing to a file, what does your method(s) look like that does this? That's where I would look first.
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Hashtable to set key and data. Then I am writing to hard disk. The key is NAME and data is name, second key is ADDRESS and data for that is e-mail address. The name of the file will be same as name of person.
Thanks,
Angle
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have one Hashtable that holds two keys, the username and the address. So let's say I create jason adam as a username, with an address of jason@javaranch.com. A hashtable gets created that holds key: jason adam, value: jason adam (in whatever object you are using), and key: jason@javaranch.com, value: jason@javaranch.com. This hashtable is then written to a file called jason adam.
Now, I create a new jason adam, with address jason@whatever.com. You want there to be two files called jason adam, so that I can retreive both emails?
Guess I'm not following exactly what it is you are looking for. Could you give a whole scenario of what is to happen?
[ April 24, 2002: Message edited by: jason adam ]
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have created address with name let's say
Angela D'souza and e-mail address angela@javaranch.com on browser. This will store in Hashtable with Key: NAME Value : Angela D'souza and another Key:ADDRESS Value : angel@javarach.com. Then I write this into file Name Angela D'souza.
Now for some reason I entered same name let's say Angela D'souza and e-mail address angela@xyz.com. This will store in Hashtable with Key : NAME Value:Angela D'souza and another Key : ADDRESS Value : angela@xyz.com.Then I write this into file name Angela D'souza. But file will be existed so this new e-mail address will overwrite old e-mail address. I don't want to overwrite this, how can I avoid overwriting?
Hope this helps,
Please let me know if you need more information,
Thanks
Angela
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, NOW I understand Sorry, been a long week.
Assuming that you have an ObjectOutputStream created with a FileOutputStream, do this:
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream( "file.name" , true ) );
That true as the second parameter allows you to append to the file. If that isn't there, it automatically overwrites the current object.
Allowing it to append will create two Hashtable objects in your file. I would imagine setting up a loop to continually read from the file, and storing your Hashtables in some collection, would be a good way to get everything that may be in there.
Does that work for ya?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!