什么是Java7 WatchService的好替代品?



我需要选择一个类似于Java7上可用的监视服务的框架。什么是跟踪文件系统更改的好替代框架 t.

提前致谢

您可以使用 JNotify 事件库 。它允许java应用程序侦听文件系统事件,例如创建,修改,重命名,删除。

j通知链接

如果你使用nodeJS。乔基达尔很有趣.围绕节点的整洁包装器.js fs.watch/fs.watchFile。

var chokidar = require('chokidar');
var watcher = chokidar.watch('file or dir', {ignored: /[/\]./, persistent: true});
watcher
  .on('add', function(path) {console.log('File', path, 'has been added');})
  .on('addDir', function(path) {console.log('Directory', path, 'has been added');})
  .on('change', function(path) {console.log('File', path, 'has been changed');})
  .on('unlink', function(path) {console.log('File', path, 'has been removed');})
  .on('unlinkDir', function(path) {console.log('Directory', path, 'has been removed');})
  .on('error', function(error) {console.error('Error happened', error);})
// 'add', 'addDir' and 'change' events also receive stat() results as second argument.
// http://nodejs.org/api/fs.html#fs_class_fs_stats
watcher.on('change', function(path, stats) {
  console.log('File', path, 'changed size to', stats.size);
});
watcher.add('new-file');
watcher.add(['new-file-2', 'new-file-3']);
// Only needed if watching is persistent.
watcher.close();
// One-liner
require('chokidar').watch('.', {ignored: /[/\]./}).on('all', function(event, path) {
  console.log(event, path);
});

使用 commonIO

开始看:http://andreinc.net/2012/06/30/writing-a-simple-file-monitor-in-java-using-commons-io/

相关内容

  • 没有找到相关文章

最新更新