Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help reading text into hashmap!

hamboogerhambooger Posts: 2Member
Hey everyone. I'm at the point where in this program I need to read a textfile and place the entries into a hashmap.
this is the txt example
1<>John Kane
2<>Jane Lyman
3<>Peter Hansen
4<>Cathy Harris

I've designed the main app which is the GUI. I have several text areas where I need to display the name only.

On a separate class I need to have it handle the I/O, with buffered reader and read each text files line by line and place them into a hashmap skipping the "<>." Then some how have it displayed in the text areas... can anyone help me out on this?


Comments

  • WirusWirus Posts: 10Member
    Just one of possible ways:

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.HashMap;
    import java.util.Map;



    public class Test {
    public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader( new FileReader( "E:/test.txt" ));
    String line = null;
    Map result = new HashMap();
    while( (line = reader.readLine()) != null ){
    String[] arr = line.split( "<>" );
    result.put( arr[0], arr[1] );
    }
    }

    }

  • WirusWirus Posts: 10Member
    Just one of possible ways:

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.HashMap;
    import java.util.Map;



    public class Test {
    public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader( new FileReader( "E:/test.txt" ));
    String line = null;
    Map result = new HashMap();
    while( (line = reader.readLine()) != null ){
    String[] arr = line.split( "<>" );
    result.put( arr[0], arr[1] );
    }
    }

    }

Sign In or Register to comment.