File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Tokenized Data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Tokenized Data " Watch "Tokenized Data " New topic
Author

Tokenized Data

Savio Mascarenhas
Ranch Hand

Joined: Nov 29, 2000
Posts: 108
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

Joined: Jun 13, 2000
Posts: 3340
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).]


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
Savio,
This will do what you want...


-Peter

[This message has been edited by Peter Tran (edited January 04, 2001).]
Savio Mascarenhas
Ranch Hand

Joined: Nov 29, 2000
Posts: 108
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

Joined: Jan 02, 2001
Posts: 783
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

Joined: Nov 29, 2000
Posts: 108
Thanks everyone for ur suggestions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tokenized Data