i need to pick a frameWork similar to watch service available on Java7 . what's a good alternative framework t to track changes on file System .
thanks in advance
i need to pick a frameWork similar to watch service available on Java7 . what's a good alternative framework t to track changes on file System .
thanks in advance
您可以使用 JNotify 事件库。它允许 java 应用程序监听文件系统事件,例如创建、修改、重命名、删除。
如果你使用 nodeJS。 Chokidar非常有趣。node.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/