Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Tokenized Data

 
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks everyone for ur suggestions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!