相关疑难解决方法(0)

文件观察器在一段时间后停止工作

我想听听文件系统中发生的变化.我正在使用FileObserver.Here是我的代码:

码:

class MyDirObserver extends FileObserver {
    String superPath;
    public MyDirObserver(String path) {
        super(path, ALL_EVENTS);
        this.superPath = path;
    }


    public void onEvent(int event, String path) {
        Log.e("onEvent of Directory", "=== onEvent ===");
        try {
            _Dump("dir", event, path, superPath);
        } catch (NullPointerException ex) {
            Log.e("ERROR", "I am getting error");
        }
    }
}


private void _Dump(final String tag, int event, String path, String superPath) {
    Log.d(tag, "=== dump begin ===");
    Log.d(tag, "path=" + path);
    Log.d(tag, "super path=" + superPath);
    Log.d(tag, "event list:"); …
Run Code Online (Sandbox Code Playgroud)

android fileobserver

3
推荐指数
1
解决办法
5628
查看次数

当文件被删除并再次创建时,inotify将停止监视文件

使用inotify时遇到一些问题.我使用inotify来监视文件的变化.这是我的代码:

int fd = inotify_init();
int wd = inotify_add_watch(fd, "/root/temp", IN_ALL_EVENTS);
int bufSize = 1000;
char *buf = new char[bufSize];
memset(buf, 0, sizeof(buf));
int nBytes = read(fd, buf, bufSize - 1);
cout << nBytes << " bytes read" << endl;
inotify_event *eventPtr = (inotify_event *)buf;
int offset = 0;
while (offset < nBytes)
{
    cout << eventPtr->mask << endl;
    offset += sizeof(inotify_event) + eventPtr->len;
    eventPtr = (inotify_event *)(buf + offset);
}
delete []buf;
Run Code Online (Sandbox Code Playgroud)

如果我删除"/ root/temp"并重新创建这样的文件,则inotify不会监视此文件的任何更改,这是怎么回事?谢谢.

c++ inotify

2
推荐指数
2
解决办法
3978
查看次数

标签 统计

android ×1

c++ ×1

fileobserver ×1

inotify ×1