Access ASCII file using a key
1 posts in topic
Flat View  Flat View

Posted By:   Manju_k
Posted On:   Thursday, December 12, 2002 09:57 PM

I have an ASCII file of huge size and need to read a particular record based on the key. The file is of fixed length and I don't want to go through all the records and compare the key field.
Is there any way of doing it? In COBOL it is possible to read a record if i have a key field.

Re: Access ASCII file using a key

Posted By:   Stephen_Ostermiller  
Posted On:   Friday, December 13, 2002 06:28 AM

If you don't want to go through the whole file, the key you want must be at a known offset or

  1. The fields must all be the same length

  2. The fields must be sorted

In either case you will want to use a RandomAccessFile and use the seek() method to go to a specific spot in the file. If the field is in a known location you can seek there. In the sorted case, you can do a binary search to find it.
About | Sitemap | Contact