0

I'm currently trying to read a game-log file. I'd like to store the "newest" part / the newly added part of the file in a String without loading the entire file, because that would cause a lot of RAM and CPU usage to process. I've tried multiple solutions like loading every line in an ArrayList<String>, or loading the entire file and creating a substring without the "checked" part. As I said that's not a suitable solution if the file is too large (up to millions of lines). Any ideas?

Log.txt contains at 9:00:00am:
    [LOG\OUTPUT] test1
    [LOG\OUTPUT] test2
    [LOG\OUTPUT] test3
    [LOG\OUTPUT] test4

Log.txt contains at 9:00:01am:
    [LOG\OUTPUT] test1
    [LOG\OUTPUT] test2
    [LOG\OUTPUT] test3
    [LOG\OUTPUT] test4
    [LOG\OUTPUT] test5
    [LOG\OUTPUT] test6

I'd like to get:
    [LOG\OUTPUT] test5
    [LOG\OUTPUT] test6
ElDapo
  • 1
  • 2
  • What is your problem ? Getting the last line of a file ? Storing text in an ArrayList ? Tracking when the file is updated ? – vincrichaud Nov 22 '21 at 15:21
  • Does this answer your question ? https://stackoverflow.com/questions/686231/quickly-read-the-last-line-of-a-text-file – vincrichaud Nov 22 '21 at 15:34
  • Have you considered using RandomAccessFile (https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/RandomAccessFile.html)? This way you can keep a pointer at the last consumed data and use it to read incremental appends – David Soroko Nov 22 '21 at 15:35

0 Answers0