Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing hash table into a file

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Well can anyone tell me that how to store the content of a HASH TABLE's content into a file. There after how to see the contents of that file.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the keys and values of the map are all String objects, and the keys do not have any spaces in them, you can use java.util.Properties. This is basically a Hashtable, and has its own methods for storing and loading.

You could also write the hash table (please use HashMap instead of Hashtable) to an ObjectOutputStream, but then you need an ObjectInputStream to be able to read it again.
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
Thanks for your quick reply. I tried in the same way, but i am unable to see the content of the file , i mean file is having some vague data. So please help me out.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should look at Properties.

You can use .toString() / String.valueOf(...) to convert your keys and values to Strings (if they aren't already), but that still leaves the required absence of spaces in your keys.

Remember, text files can only represent Strings. They may appear to you as numbers or something else, but in the end they are still Strings.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic