用于监视文本文件中的更改的 Java 代码

发布于 2024-11-17 15:59:31 字数 145 浏览 0 评论 0原文

我需要编写一个java代码来检测对文本文件所做的更改,并在文本文件更改时通知对文本文件所做的更改,即)如果文本文件中的单词ABCD更改为BCDA,那么我需要请注意,ABCD 更改为 BCDA。你能让我知道我是否可以使用java实现这一点(仅使用开源工具,不使用付费或商业工具)

I need to write a java code which detects changes done to a text file and also notify what change was done to the text file when the text file is changed ie) If a word ABCD was changed to BCDA in the text file then i need to be notified that ABCD was changed to BCDA. Can you please let me know whether i can achieve this using java(using only opensource and no paid or commercial tools)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你没皮卡萌 2024-11-24 15:59:31

请参阅 http: //commons.apache.org/io/api-release/index.html?org/apache/commons/io/monitor/package-summary.html 一个可以让你监视文件的开源库进行更改。

编辑:请注意,这将报告发生了更改,但不报告更改的特定行。如果您希望实时进行比较,您可能必须自己运行比较:我不确定是否存在任何预先打包的代码可以为您进行比较。

See http://commons.apache.org/io/api-release/index.html?org/apache/commons/io/monitor/package-summary.html for an open-source library that will let you watch a file for changes.

EDIT: Note that this will report that a change occured, but not the specific line that changed. If you want a diff to occur in real time you'll probably have to run the diff yourself: I'm uncertain any prepackaged code exists that will do the diff for you.

℉服软 2024-11-24 15:59:31

如需更标准的解决方案,您还可以查看JSR 203 backport for Java 6。它提供文件扫描器功能,与即将推出的 Java 运行时兼容。

For a more standard solution, you can also take a look at JSR 203 backport for Java 6. it provides File Scanner facility, compatible with upcoming Java runtime.

殊姿 2024-11-24 15:59:31

听起来你想运行实时差异。

跟踪文件的“旧”版本。然后编写一段每 5 分钟运行一次或根据您需要的细粒度运行的代码。使用您自己的方法或库方法在这两个文件之间运行差异(请参阅 java- diff-utils)。

Sounds like you want to run a real-time diff.

Keep track of the "old" version of the file. Then have a piece of code that runs every 5 minutes or however fine-grained you need. Run a diff between these two files using either your own method or a library method (see java-diff-utils).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文