如何检测文本文件的实时变化? [英] How to detect real-time change of text files?

查看:278
本文介绍了如何检测文本文件的实时变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我指出来写一个小PC工具读取日志使用C#或Java文件。日志文件将在.txt格式。在应用程序运行,写日志,我想我的工具,在同一时间打开日志,当一个新行被写入日志文件的自动刷新。

I am stating to write a little PC tool to read log files using c# or java. The log files will be in .txt format. An application is running and writing logs, and I want my tool to open the log at the same time and refresh automatically when a new line is written to the log file.

我的挑战是,如何检测日志文件中的变化,使我的工具将具备实时显示能力吗?这是一个普遍的问题,但伪codeS将大大AP preciated!

My challenge is, how do I detect the log file changes so that my tool will have real-time displaying ability? This is a general question but pseudo codes will be greatly appreciated!

推荐答案

您可以使用 FileSystemWatcher的类(的 MSDN页面)。不过要小心,如果你尝试,而其他进程写,你可能会被拒绝访问的文件,打开该文件。

You can use the FileSystemWatcher class (MSDN page). Be careful though, if you try to open the file while the other process is writing the file you will probably be denied access.

这篇关于如何检测文本文件的实时变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆