创新互联鸿蒙OS教程:鸿蒙OSFileWatcher

FileWatcher

java.lang.Object

|---ohos.utils.FileWatcher

public class FileWatcher
extends Object

提供监控指定文件目录状态变化的能力。

要监控文件,首先需要实现 FileWatcher.EventHandler 类,该类处理被监控文件目录的状态变化事件。 然后,您应该使用 addWatch(java.nio.file.Path,ohos.utils.FileWatcher.EventHandler,boolean,java.nio.file.WatchEvent.Kind...) 方法添加要监视的文件目录和 关联的事件处理程序。 当指定目录中的文件发生更改时,将触发事件处理程序来处理该事件。

FileWatcher 支持 StandardWatchEventKinds 中定义的以下事件:

  • StandardWatchEventKinds.ENTRY_CREATE
  • StandardWatchEventKinds.ENTRY_DELETE
  • StandardWatchEventKinds.ENTRY_MODIFY

嵌套类摘要

修饰符和类型 描述
static interface FileWatcher.EventHandler 提供处理文件事件的处理程序。

构造函数摘要

构造函数 描述
FileWatcher() 默认构造函数用于创建文件观察者实例。

方法总结

修饰符和类型 方法 描述
void addWatch(Path directory, FileWatcher.EventHandler eventHandler, boolean isRecursive, WatchEvent.Kind... events) 添加监视程序以监视指定的文件目录。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

构造函数详细信息

FileWatcher

public FileWatcher()

默认构造函数用于创建文件观察者实例。

Throws:

Throw名称 Throw描述
RuntimeException 如果没有文件观察器服务,则引发此异常。

方法详情

addWatch

public void addWatch(Path directory, FileWatcher.EventHandler eventHandler, boolean isRecursive, WatchEvent.Kind... events)

添加监视程序以监视指定的文件目录。

您可以指定要监视的文件事件。 如果未指定事件,则监视文件目录上的所有事件。

参数:

参数名称 参数描述
directory 指示要监视的文件目录。
eventHandler 指示要添加指定文件目录的事件处理程序。
isRecursive 指定是否递归监视指定的文件目录。

Throws:

Throw名称 Throw描述
NullPointerException 如果 directory 或 eventHandler 为 null,则引发此异常。
RuntimeException 如果添加观察者失败,就会引发此异常。

本文标题:创新互联鸿蒙OS教程:鸿蒙OSFileWatcher
URL地址:http://bzwzjz.com/article/djjipej.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 定制网站建设多少钱 成都网站设计公司 成都网站制作 四川成都网站建设 网站设计公司 成都定制网站建设 网站建设改版 成都网站建设流程 网站建设方案 外贸网站建设 成都企业网站建设 营销网站建设 网站建设方案 成都商城网站建设 成都模版网站建设 网站制作 重庆网站制作 手机网站设计 专业网站设计 泸州网站建设 成都网站设计公司 高端网站设计推广