This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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: 15299

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!
GeeCON Prague 2014
subject: Reading contents of file into a Map