Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading txt file and Searching for records

 
muhsin sabeer
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!