How to detect the change of text files in real time?

I declare that I want to write a small tool to read files using C # or java. Log files will be in .txt format. The application starts and writes logs, and I want my tool to open the log at the same time and automatically update when a new line is written to the log file.

My task: how to detect changes to the log file so that my tool can display in real time? This is a general question, but pseudo-codes will be very grateful!

+4
source share
3 answers

You can use the FileSystemWatcher class (

+7
source

There are a bunch of these questions and answers too:

Reading content content changes in .NET

Your goal is a FileStream object, I suppose.

+4
source

I would poll the file and check its metadata for the last modified date or, if you use .NET, you can use the FileSystemWatcher class

+1
source

Source: https://habr.com/ru/post/1443529/


All Articles