2

How to monitor file or directory changes?

Share:

Filed in: Java IO
  • Srin

    Found this a very useful example to understand watchservice..

    In the SOP , i added event.context() to know what file has changed.

    if (kind == ENTRY_CREATE) {
    System.out.println(“Entry was created on log dir.:”+event.context());
    } else if (kind == ENTRY_MODIFY) {
    System.out.println(“Entry was modified on log dir.:”+event.context());
    } else if (kind == ENTRY_DELETE) {
    System.out.println(“Entry was deleted from log dir.:”+event.context());
    }

    • Srin

      I apologize ; In your next article i see the example to know the file name.
      ((Path)event.context()).getFileName()

      Thanks for your examples.

© 8936 Java Examples - Built with love by Wayan Saryada.