挂接到文件中,实时读取新内容 [英] hook into a file, read new content in real time

查看:68
本文介绍了挂接到文件中,实时读取新内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何挂接到另一个程序中并不断写入该文件的当前文件中?假设有一个10行的文本文件。启动我的应用程序时,每次编写程序保存其内容时,它都必须检测并从中读取任何内容。可以在不不断检查文件大小/日期的情况下完成此操作吗?

How would I hook into a file that's currently in use by another program, which constantly writes out to it? Let's say, there's a text file with 10 lines. When I start my app it has to detect and read any content from there on everytime the writing program saves its content. Can this be done without a constant check on the filesize/date?

推荐答案

您可以使用ReadDirectoryChangesW API监视文件夹中的更改。

You could monitor the folder for changes using the ReadDirectoryChangesW API.

跟踪您最近读到的位置,并且当您收到该文件的更改通知时,请从该位置读取到文件末尾(与当前位置相同)

Keep track of the last position you read to, and when you receive a change notification for that file, read from there to the end of the file (as it currently stands).

如何使用ReadDirectoryChangesW API的示例在此处:

An example of how to use the ReadDirectoryChangesW API is here:

为什么ReadDirectoryChangesW忽略事件?

这篇关于挂接到文件中,实时读取新内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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