Results 1 to 2 of 2
Thread: Random access to text file
- 11-05-2008, 08:49 PM #1Member
- Join Date
- Aug 2008
- Rep Power
Random access to text file
I have a text file where each line correspond to a specific entry. Unfortunately, lines are of variable size.
At some point, I need to access entry X, which I know to be at line X in my text file. Unfortunately, I have no clue what is the byte position of entry X. Of course, I want to avoid reading all of the X-1 first lines.
I am wondering if there is any way to access a text file randomly based on line number instead of byte position ?
If not, suggestions are welcome.
An obvious solution would be to keep an index file with entries of the form:
"Entry X : byte position of entry X in data file"
So each line of the index file has a constant size.However, this is a bit tedious as modification to the main file implies modification of the whole index file.... other solutions ?
- 11-05-2008, 09:53 PM #2solution would be to keep an index file
The index file would require a one time scan of the file to find and save the location of each line. If the length of a line were changed, the index for the following lines would have to be adjusted accordingly.
- By gezzel in forum New To JavaReplies: 2Last Post: 09-19-2008, 05:04 PM
- By explosion242 in forum New To JavaReplies: 2Last Post: 09-18-2008, 02:48 PM
- By Rgfirefly24 in forum New To JavaReplies: 2Last Post: 04-24-2008, 11:07 PM
- By AralX in forum New To JavaReplies: 2Last Post: 12-25-2007, 08:04 PM