bbholzbb
bbholzbb

Reputation: 1932

Getting Java Filesystem-Folder onchange event (Like Dropbox)

I want to sync a folder like Dropbox. If in my Folder is changed a file or a folder, I want to get an Event, which starts my synchronisation Class. How can I get such an Event without scanning this folder by an Intervall?

Upvotes: 0

Views: 301

Answers (2)

jarnbjo
jarnbjo

Reputation: 34323

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.

Upvotes: 1

Arpit
Arpit

Reputation: 12797

Some start for you:

get the list of all files : yourdir.listFiles()

now for each file in filelist: file.getLastModified()

if it is equal to current time or differ from lastSynctime(you need to maintain it in your sync class) then sync it.

Upvotes: 0

Related Questions