无限文件监视器

编程入门 行业动态 更新时间:2024-10-21 19:46:10
本文介绍了无限文件监视器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我试图在Dart中实现文件监视器。问题是,我不知道如何使流永远的列表。在我的代码 print 语句仅在文件更改时触发一次。我尝试了 while(true){} ,但没有影响。

Hello I'm trying to implement file watcher in Dart. And the problem is that I can't figure out how to make forever lister for stream. In my code print statement fires only once, when file was changed. I tried while(true){} but didn't make affect.

import "dart:io"; void main(){ List<String> paths = ['any.dart']; paths.forEach((fp){ File f = new File(fp); f.watch().listen((e){ print(e); }); }); }

Dart信息: Dart VM版本:1.4.0 (Tue May 20 04:56:35 2014)onlinux_x64

推荐答案

查看watch函数的文档:

Please have a look into the doc of the watch function:

The implementation uses platform-dependent event-based APIs for receiving file-system notifications, thus behavior depends on the platform. * Windows: Uses ReadDirectoryChangesW. The implementation only supports watching directories. Recursive watching is supported. * `Linux`: Uses `inotify`. The implementation supports watching both files and directories. Recursive watching is not supported. Note: When watching files directly, delete events might not happen as expected. * `Mac OS`: Uses `FSEvents`. The implementation supports watching both files and directories. Recursive watching is supported.

这意味着这不会在Windows上工作。对于你的问题,它说:

This means this won't work on Windows. For you problem it says:

The returned value is an endless broadcast [Stream], that only stops when one of the following happends: * The [Stream] is canceled, e.g. by calling `cancel` on the [StreamSubscription]. * The [FileSystemEntity] being watches, is deleted.

这意味着您的文件被删除,流被取消或这是一个错误,

This means either your file got deleted, the stream got canceled or this is a bug and you should file a ticket for this.

在Windows上没有任何反应。在Mac我得到这与您的代码:

On Windows there is no reaction for me. On Mac I get this with your code:

FileSystemModifyEvent('test_file_watcher.dart', contentChanged=true) FileSystemModifyEvent('test_file_watcher.dart', contentChanged=true) FileSystemModifyEvent('test_file_watcher.dart', contentChanged=true) FileSystemModifyEvent('test_file_watcher.dart', contentChanged=true) FileSystemModifyEvent('test_file_watcher.dart', contentChanged=true) FileSystemModifyEvent('test_file_watcher.dart', contentChanged=true)

$ b b

如何测试你的代码?我简单地编辑和保存我的文件。所以它的工作对我很好。您使用哪个版本?

How do you test your code? I simple edited and saved my file. So it's working great for me. Which version are you using?

回报 Robert

Regards Robert

更多推荐

无限文件监视器

本文发布于:2023-11-11 06:12:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:监视器   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!