File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Storing hash table into a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Storing hash table into a file" Watch "Storing hash table into a file" New topic
Author

Storing hash table into a file

kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
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

Joined: Oct 27, 2005
Posts: 19792
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
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

Joined: Oct 27, 2005
Posts: 19792
    
  20

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
 
subject: Storing hash table into a file