FIlewatcher in java

Posted on 2009-02-21
Last Modified: 2012-05-06

In my project is in Java and there It is required to get a list of all files after specific time say get all xml's files
from the directory after modify timestamp 08 February 2009, 19:18:20

Yes, there are 1000's of files in this directory, so i don't want to check all the files again

Also I donot wanted to include sub-directories of the folder

I assume that file watcher can help me on this, whch will raise an event as soon as file is created or modified in the path

I searched and found one URL

Here I can find file watcher

But I am getting running this application

Error says

C:\java\FileWatcher\1>java DirectoryWatcher
Exception in thread "main" java.lang.NoClassDefFoundError: DirectoryWatcher
Caused by: java.lang.ClassNotFoundException: DirectoryWatcher
        at$ Source)
        at Method)
        at Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: DirectoryWatcher.  Program will exit.


Can anyone help me on this

If someone has more better option to do it

Many Thanks
Question by:tia_kamakshi
    LVL 9

    Expert Comment

    You have to place all the java code in this directory

    this is because the all the code sit in
    package com.lightspeedleader.directorywatcher;

    Author Comment

    many thanks for your response

    I am not remembering, there is command in javac *.java which automatically creates packages for you when you compile with it.

    Since I was not able to find that command
    I have deleted package com.lightspeedleader.directorywatcher; line from all the files and compiled this again
    and got the same problem

    Can you please download and this for me

    Many Thanks
    LVL 9

    Expert Comment

    The downloaded zip file (
    only contain path directorywatcher\

    therefore you have to manually create

    Author Comment

    Please see my comments above..

    Looks we both have posted comments at same time
    LVL 9

    Expert Comment

    I have remove the line
      package com.lightspeedleader.directorywatcher;
    from all java files it work for me.

    You can download my test file from
    LVL 9

    Accepted Solution

    Or you can download the correctly zipped file


    Both solution work for me.

    Author Closing Comment

    Many Thanks It works great

    Author Comment


    I skipped, Is it possible that this code watches multiple directories rather than 1 directory

    Many Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    how to disable hibernate query cache 2 52
    Convert ArrayList of custom objects to JSON 4 44
    matchUp  challenge 9 47
    wordsWithout 49 63
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now