• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help reading text file into hashmap

 
sam t. yang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there. I've been given a project to due that involves working with textfiles.
The text files are given in the following structure

ID1<>NAME1
ID2<>NAME2
ID3<>NAME3

Supposedly I'd have a separate class that does I/O and Hashmaps. I have an idea with the i/o codes but don't know how to deal with hashmaps.
I need to display the NAME part only in a text area without the ID or <>, so I should have a method converts the TXT file into hashmap, and then return the name part as an array?
Any help as appreciated !

 
Viktor Kubinec
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just read line by line, store id and name as a String and do something like this :



and than for every line



for looping through hashmap you can do this :



for more just google for hashmap and collections tutorials, there are lots of these out there
 
sam t. yang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the response. I'll try it out, but most likely will run into more questions
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam t. yang wrote:Hey there. I've been given a project to due that involves working with textfiles.
The text files are given in the following structure:
ID1<>NAME1
ID2<>NAME2
ID3<>NAME3

I presume you mean that the lines have that format.

If so, I'd also look at String.split() for extracting the information from the lines.

Winston
 
sam t. yang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


now that's what i have so far... but need to display the results onto my main class. any help with that?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch (sorry it’s late) and have a look at the Java Tutorials, which tell you how to iterate the entries or keys or values in a Map.
 
sam t. yang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for all the responses. I have made much progress
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic