'Read Large file in Chunks and Compare each line in Java

I have a text file with entries like below.

{"id":"event1","state":"start","timestamp":"11025373"}
{"id":"event1","state":"end","timestamp":"11025373"}
{"id":"event2","state":"start","timestamp":"11025387"}
{"id":"event3","state":"start","timestamp":"11025388"}
{"id":"event3","state":"end","timestamp":"11025391"}
{"id":"event2","state":"end","timestamp":"11025397"}

I want to read the file as input and compare the time consumed by each event using Java. Like event1 has taken (11025373 - 11025373) = 4ms time. (start - end) event2 has taken (11025397 - 11025387) = 10ms time.

I initially thought to read line by line.

File file = new File("C:\\Users\\xyz\\inputfile.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null)
LOGGER.info(line);

Considering the input file size can be very Large is this the right approach?. Any suggestion for best apporach will be helpful. And also how to compare each object in the file, i.e. compare "start" of event1 to "end" of event1 if I go line by line.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source