0

我想同步一个像 Dropbox 这样的文件夹。如果在我的文件夹中更改了文件或文件夹,我想获得一个事件,它启动我的同步类。如何在不通过 Intervall 扫描此文件夹的情况下获得这样的事件?

4

2 回答 2

1

You have at least two options. You can either reinvent the wheel as Arpit suggested or you can also use the WatchService API.

You can find a WatchService tutorial here.

于 2013-02-20T15:51:59.233 回答
0

一些开始为您服务:

获取所有文件的列表:yourdir.listFiles()

现在对于文件列表中的每个文件: file.getLastModified()

如果它等于当前时间或不同于lastSynctime(您需要在同步类中维护它)然后同步它。

于 2013-02-20T15:48:16.973 回答