Last Updated: February 25, 2016
·
811
· georgeosddev

Schwatcher: File-watching library for Scala. Built on Java 7's WatchService and Akka actors.

Schwatcher

A library that wraps the WatchService API of Java7 and allows callbacks to be registered on both directories and files.

Xitrum contain Schwatcher inside it, and provide quick utility.

import xitrum.util.FileMonitor

val target = FileMonitor.pathFromString("path_relative_to_application_root")
FileMonitor.monitor(FileMonitor.MODIFY, target, { path =>
  // Do some callback with path
  println(s"File modified: $path")

  // And stop monitoring if necessary
  FileMonitor.unmonitor(FileMonitor.MODIFY, target)
})