• 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

Reading txt file and Searching for records

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have text file with many fields like below (21 Fields):

The file is bigger in size (10MB).
I have to find a record from this file. The records in the file are duplicated. The searching of record by any field which will be given by user. I have follwoing doubts on accomplishing this:
1) which is the best way to read & load the records from file?
(I have to store all the fields separately!!)
2) Which searching method is best opt for this?

Please advice me the hint. And I will develop it.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This could easily be a book-length topic. You need to solve several distinct problems. I strongly urge you to work them out one at a time!

You need some kind of structure for records in the file. Maybe delimited fields, fixed length fields, XML tags, serialized objects or many other choices.

You need some kind of structure for records in memory. A simple Java object with 21 fields or a Map would work.

You need to read the file structure and construct the in-memory structure. And probably write the in-memory data back to disk.

10 mb is not all that big, so reading it all into memory is not out of the question. A List of some kind could probably hold it all. Whether you read it all into memory or read one line at a time process it and throw it away you need some kind of search. The details will depend on your storage.

Any of those problems sound like something you could take a shot at? Again, pick ONE and show us how you think you'd do it.

Oh, and think about a database. This is exactly what they are there for!
 
muhsin sabeer
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fields are separated by space. And I am trying to work with java.util.regex . The program will read the file line by line and scan the pattern for the field given by user, so the user can user wild-cards. If it found then append it to Vector else throw away. The result set will display to user. The display set has only about 7 fields.

I am started coding now and get back ur assistant when I stuck again.

Thanks again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic