• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to read a line and store the data!

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, the input text file is like this:

KWAFZRMYC 195.08 s 400 0
EDWWKTMYC 195.09 s 400 0
JSQPPHMYC 195.05 s 200 0
LQHTFMMYC 194.95 b 600 1
BTQFADMYC b 500 1
ZOOKNLMYC 195.07 b 400 1
TVZKDZMYC 195.01 b 300 1

First of all, how to read read this file line by line?

After read the file, I need to store them line by line and seperate by space, what data structure recommend, linked list?


Thanks in advance!
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the best thing you can do is to get a copy of the API docs (if you do not already have them) and check out the classes that have to do with streams and files. There are many of them, and they can be combined in various ways to read files into arrays of chars, etc. Java tends to treat I/O as a stream, and you have so many different ways of doing it I won't even try to give any code example. As for parsing and storing the read-in file, there is the String class (as well as others like StringBuffer that simplify some operations), and this type of thing has been done SO many times you shouldn't have much trouble finding loads of examples to help you understand it all. For that matter, you could probably just search this site and find all you need, but I'm new here so I have not had a chance to check out everything there is. That may not help as much as you would like, but a little research should give you plenty to get ideas from, and solving this by using the existing Java classes and trying different things will give you much-needed experience rather than just having someone give you ready-made code!
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sheng,

An excellent place to start learning about File IO is the JavaRanch IO FAQ, which has lots of great links to places to learn more.

As to the best data structure to use to store your data once it is read in, that depends on what you need to do with it. What are you going to use it for? Do you need to sort it? To you need to iterate through the items? The answers to these questions will help you start to figure out the best Collection implementation to use.
 
sheng zhong
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys!
reply
    Bookmark Topic Watch Topic
  • New Topic