aspose file tools*
The moose likes I/O and Streams and the fly likes how to write the hashtable to a 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 "how to write the hashtable to a file" Watch "how to write the hashtable to a file" New topic
Author

how to write the hashtable to a file

jack zhang.China
Greenhorn

Joined: Mar 15, 2006
Posts: 5
hello guys:
i want to write a hashtable to a file,but didn't know how
Kia Phia Ben
Ranch Hand

Joined: Dec 16, 2005
Posts: 48
I think I loop Enumeration and get value from key. Next step you write file.
Martin Simons
Ranch Hand

Joined: Mar 02, 2006
Posts: 196
Simply write the hashtable.toString() string to a file.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

Do you intend to read it back later? Martin's solution isn't very useful when your program has to read it back later.

Does the output have to be in text format or can it also be binary?

See the Java Tutorial on serialization for an alternative solution.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Martin Simons
Ranch Hand

Joined: Mar 02, 2006
Posts: 196
Actually with the format that is written using toString on a hastable
it is not hard at all to read it back with a simple parser, which then
allows you to make it human readable and still be reusable. It is not
true serializing, true, but I also did not mean it to be.
 
wood burning stoves
 
subject: how to write the hashtable to a file