How to track changes (and most important read) really big files in Java efficiently -
i have big log file in text form, created 3rd party app. unfortunately file 150mb, others may have bigger files, depending on day started logging. since file created 3rd party application can't modify in way (remove of it's oldest content example).
what want keep track of file size , notified when there new line added (thus size of file altered) , read line (it last line).
i know when want keep track of changes, doesn't have constant update, when user has application minimized in tray. essentially, want notify user changes in state of application when dcan't see them.
now tracking differences in size of file using
file file = new file("filepath"); file.length();
as far understand doesn't load file memory it's not of performance drop.
if right what efficient way read last line
of file?
replace efficiency "as low performance drop possible". don't mind 2 or 3 seconds delay between actual event being logged file , user being notified.
you can use directorywatcher notified of change directory or file. can use randomaccessfile wind position e.g. read last byte, , read bytes point. can use deprecated readline() method if particularly care encoding.
otherwise suggest copy whole lines buffer e.g. bytearrayoutputstream , decode using right encoding.
there reason want copy first youc incomplete lines or incomplete multi-byte characters bufferedreader doesn't handle particularly well.
Comments
Post a Comment