I'm trying to write a program that will read a VERY LARGE binary file and try to find the occurrence of 2 different strings and then print the indexes that matches the patterns. For the example's sake let's assume the character sequences are [H,e,l,l,o]
and [H,e,l,l,o, ,W,o,r,l,d]
.
I was able to code this for small binary files because I was reading each character as a byte and then saving it in an Arraylist
. Then starting from the beginning of the Arraylist
, I was comparing the byte arraylist(byte[] data)
with the byte[] pattern
.
I need to find a way to do the same but WITHOUT writing the entire binary file in memory for comparison. That means I should be able to compare while reading each character (I should not save the entire binary file in memory). Assume the binary file only contains characters.
Any suggestions on how this can be achieved ? Thank you all in advance.