Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tokenized Data

 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A ".txt" file needs to be read line-by-line where,each line contains data seperated by a token(,).The data on reading needs to be stored in a Collection class.The Data could be something like this -
BILL_NO,N,5, 0, "Bill No.",abc
RCPT_NO,N,5, 0, "Receipt No.",xyz

Should the data columns be stored in "seperate" Collection instances ??? Which Collection class would be most appropriate ??? Which InputStream would be most suitable to read this tokenized data ???
Pls let me know ur views.
Thanks.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a lot of ways this could go depending on things still left unask and unanswered. From what I see the best way to do this is to create an Object that represents each row. The data looks to me to be appropriate for using BufferedReader to read in each line and StringTokenizer to parse each data element out of each row. As for a seperate Collection class for each column, You could do that but it will definately make life hard on you trying to associate the data from one collection to the related data from another so, I think keeping it all in one collection is best.
As for which collection, is there a key that is unique to each row?
Do you need the data sorted in any particular order?
Is navigation speed the highest priority?
Answer these and any other data relates questions and you should be able to narrow down your possiblities.
StreamTokenizer could be used but, it is pretty set on what it considers tokens and I don't think looking at your data that utilizing it would be easier or safer than the method I laid out above.
Hope this helps
[This message has been edited by Carl Trusiak (edited January 04, 2001).]
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Savio,
This will do what you want...


-Peter

[This message has been edited by Peter Tran (edited January 04, 2001).]
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
How should data be read from any particular random position in the file say,from the line after the word "xyz.dat" is found to the line before #end(line 22). ???
1.
.
;---This is a Comment - ignore line----
.
9.
10.#begin "abc.dat"
11.Name
12.Address
13.PhoneNo.
14.CCNo.
15.#end
16
17.#begin "xyz.dat"
18.PurchaseNo.
19.Date
20.Cust.Name
21.BillAmt.
22.#end
23.
24.
.
;---This is a Comment - ignore line----
27.
28.
29.
.
.
.
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most simple way is to search for some indentifying token from the String object you get in the readLine() method.
E.g. (No where near complete as my above example...I have to get back to my regular job.)

-Peter
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for ur suggestions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic