I have a text file. It is designed as following:
#1{1,12,345,867}
#2{123, 3243534, 2132131231}
#3{234, 35345}
#4{}
... (at the end of an each entry stands "\n")
That is an example. In fact my strings #number{number,number,...,number} could be really long...
Here is a template of a constructor of a class which works with this file:
public Submatrix(String matrixFilePath, int startPos, int endPos) throws FileNotFoundException{
}
As you can see submatrix is determined by startPos and endPos numbers of strings of a matrix.
My question is : "How could I count strings to reach the right one?" My file can contain billions of strings. Should I use LineNumberReader->readLine() billions times?????
I would be tempted to read each line sequentially until I reached the desired line. However, since the lines are numbered in the file and delimited with newlines you can treat the file as random access and employ various strategies. For example, you get use a variant of binary search to quickly find the starting line. You can estimate the average line length from the first N lines and then try to make a more accurate guess as to the starting location, and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With