• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating properties file by taking values from csv  RSS feed

 
imran quazi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scenario:
I'm populating a hashtable by taking values from 2 columns of a csv file. Now, I want to write the key/value into a properties file with some formatting, such as:
<code>
key = value;
</code>
I'm having problem in writing into the file as I want to loop through the hashtable until it ends, and taking the key/value pair from it.

Please suggest mer hoe to do that.
 
imran quazi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry please ignore the <code> & </code> part
 
Ricky Martaputra
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use method getKeys() in Hashtable class.
You will get all keys in your Hashtables, then get each value by its key.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just go through the API of HashMap.

You can do it with KeySet() which gives you the set of keys for which you can obtain an java.util.Iterator. With the Iterator you will get a key at a time with which you can obtain the value from HashMap by invoking the get() method while passing the key to it.

Remember: it deals with objects and NOT primitives. If in case, you may need to have a wrapper classes for the respective primitive types.
 
imran quazi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody . It worked.
 
imran quazi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody . It worked.

but I couldn't find any method as getKeys().
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by imran quazi:
Thanks everybody . It worked.

but I couldn't find any method as getKeys().


There is no such method. It is keySet() which would return a java.util.Set.
[ August 09, 2007: Message edited by: Raghavan Muthu ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!