I need to count the number of lines in a file.
The number of lines in a file will increase/decrease, so I have to check this regularly.
I have written this code into a thread to execute always.
I have opened a BufferedReader() on the file object to read the number of lines (.readLine()).
My problem is GC is running frequently if I am opening Bufferedreader() every time.
I am closing the buffer object and assigning it to NULL after usage, but still I am facing the problem.
So I dropped the idea of opening the buffer only to count the number of lines.
I used Scanner() to open the file object, But I am getting outofMemomryException with Scanner class. I have done some investigation about Scanner class and came to know that it will fail to open if file size is large. (my file will have around 200 000 lines).
Please suggest me the less expensive (in terms of memory) way of counting the number of lines from a file.