• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Tokenized Data

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, the easy part. To read this data, you'd want something like this:
<code><pre> BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
StringTokenizer columns = new StringTokenizer(line, ",");
String column1 = columns.next().trim();
String column2 = columns.next().trim();
...
}
</pre></code>
You'll need to put in some sort of exception handling. And if you can ever have a blank field represented by two adjacent delimiters (",,"), you'll need to write your own version of StringTokenizer to return a blank String "". But anyway...
For the collection, it realy depends how the data will be used. Do the columns make sense on their own, or do they only make sense when used in conjunction with other data on the same row? Probably the latter - so I'd be inclined to have a single collection of Record objects, where Record is a class you write which stores all the data on one row. Does the order of the records matter? If so, you probably want a List. Do you want to be able to find a record quickly using a unique key (e.g. bBILL_NO or RECEIPT_NO)? Then use a Map. Should the rows be sorted by some criterion? Then use a SortedList or SortedMap. As you can see, the decision of what collection class to use is based on how you want to use the class. If you're not sure, try just using an ArrayList for starters. Try to refer to it as a Collection rather than an ArrayList whenever possible though, so that if you find the need to change the type later, it will be easier.
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim,
Savio cheated and posted this question in several different forums. Anyway, check out my suggestion in the IO Forum
-Peter
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone for ur suggestions.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic