Forums Register Login

need help reading text file into hashmap

+Pie Number of slices to send: Send
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 !

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
thanks for the response. I'll try it out, but most likely will run into more questions
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send


now that's what i have so far... but need to display the results onto my main class. any help with that?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
thanks for all the responses. I have made much progress
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 18629 times.
Similar Threads
Finding poistion (Line Number) of text in a given File.
Calling variable or methods with Strings?
Confusion about interfaces, creating your own classes, casting
Using hashmap with html:options
Confusion about interfaces, creating your own classes, casting
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:10:06.