• Post Reply Bookmark Topic Watch Topic
  • New Topic

hashtable to file

 
kavins
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to write from a hashtable to a file
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just want to log it (and if the keys and values are all readable, such as Strings or Integers), just write it to a PrintWriter -> File Writer:

It prints like this
Hash table = {Key1=Value1, Key2=Value2, ... }
If you need to read it back in a program (and if the keys and values are all Serializable or Externalizable), you might want to use a RandomAccessFile <- ByteArrayOutputStream.writeObject( hashMap) or FileOutputStream <- ObjectOutputStream
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If everything (keys and values) in the Hashtable are Strings, you can shove them all in a Properties and store() it:
Properties p = new Properties();
p.putAll( theHashTable );
p.store( outputStream, "foo" );
This will only work if the hashtable is composed of only strings.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!