I want to index large text file about 1 gb, so I store in another file new line positions, to access the file later by RandomAccessFile, here is my code
while (true) {
raf.seek(currentPos);
byte[] bytes = new byte[1000000];
raf.read(bytes, 0, bytes.length);
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == 10) {
rafw.writeInt(currentPos + i);
}
}
currentPos = currentPos + sizeOfPacket;
if (currentPos > raf.length()) {
sizeOfPacket = (int) raf.length() - currentPos;
} else if (currentPos == raf.length()) {
break;
}
bytesCounter = bytesCounter + 1000000;
//Log.d("DicData", "Percentage=" + currentPos + " " + raf.length());
int progress = (int) (bytesCounter * 100.0 / folderSize + 0.5);
iDicIndexingListener.onTotalIndexingProgress(progress < 100 ? progress : 100);
Here I check all file bytes for value (10) which means "\n" new line, My big problem is: this proccess takes too much time, about 15 minutes, My question: Is there a way faster than this? Thanks