inotify-javaLinux文件系统监控的Java类库

联合创作 · 2023-09-28 21:17

inotify-java 是一个在 Linux 下对文件系统的更改进行监控的 java 库。

示例代码:

       try {
            Inotify i = new Inotify();
            InotifyEventListener e = new InotifyEventListener() {

                @Override
                public void filesystemEventOccurred(InotifyEvent e) {
                    System.out.println("inotify event occurred!");
                }

                @Override
                public void queueFull(EventQueueFull e) {
                    System.out.println("inotify event queue: " + e.getSource() +
                            " is full!");
                }
               
            };
            i.addInotifyEventListener(e);
            i.addWatch(System.getProperty("user.home"), Constants.IN_ACCESS);
        } catch (UnsatisfiedLinkError e) {
            System.err.println("unsatisfied link error");
        } catch (UserLimitException e) {
            System.err.println("user limit exception");
        } catch (SystemLimitException e) {
            System.err.println("system limit exception");
        } catch (InsufficientKernelMemoryException e) {
            System.err.println("insufficient kernel memory exception");
        }

浏览 8
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报