It's not a secret anymore!
The moose likes Groovy and the fly likes Reading contents of file into a Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Reading contents of file into a Map" Watch "Reading contents of file into a Map" New topic

Reading contents of file into a Map

Bill Lee

Joined: Feb 02, 2007
Posts: 20
I am working on a script of reading the contents of a file directly into a map. I have no issues reading into list. But basically have a file that has 2 fields separated by a comma (i.e.

Chicago, IL
Sacramento, CA

Is this something that anyone has had experience with? Thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

What are you wanting for the key and value in the map? Something like...



We need more info as to what you are trying to achieve. This is just a guess.

GenRocket - Experts at Building Test Data
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
If you want a map with the city as key and the state as value, then try this:

Best wishes!
I agree. Here's the link:
subject: Reading contents of file into a Map
jQuery in Action, 3rd edition