Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: reading file into a hashmap?

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default reading file into a hashmap?

    hi out there.
    i have a question of course, i have.
    i need to parse a textfile. this file contains the following:

    string1 = 1,2,3,4
    string2 = 22,56,77
    ...

    and so on. what i need first is the following:
    get every string and number and put that into a hashmap. can i use an array as the values for the key "string"?
    what is really intended is the following: i have to a call an external program that gets the arrays as attributes.
    example:
    "external_program -param string1=1 -param string2=22" and so on for every string.
    next loop would be in this example "external_program -param string1=1 -param string2=56" so to iterate *every* combination of the values of the arrays. and i don't know how many times the term "string =" will appear. how do i do that in java?!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,534
    My Mood
    Hungover
    Thanks
    145
    Thanked 647 Times in 552 Posts

    Default Re: reading file into a hashmap?

    Are you just asking how to iterate over a Map? If so, check out the API- there is a method that returns a set that contains all of the keys, and there is a method that returns the mapped value of a key.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: reading file into a hashmap?

    If you want to load a properties file like that have a look at Properties (Java Platform SE 6)

    // Json

Similar Threads

  1. Reading a file
    By Soccer13 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 26th, 2010, 09:55 PM
  2. Help with reading from file
    By drazenmd in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 15th, 2010, 04:43 AM
  3. Reading file
    By nasi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 3rd, 2010, 04:14 AM
  4. Anyone Help me in XML file Reading??????????
    By goplrao in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 2nd, 2010, 12:04 PM
  5. [SOLVED] Problem in reading a file from java class
    By aznprdgy in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: March 23rd, 2009, 10:31 AM