?
Solved

FIlewatcher in java

Posted on 2009-02-21
8
Medium Priority
?
1,616 Views
Last Modified: 2012-05-06
Hi,

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
http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/

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 java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown 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.

C:\java\FileWatcher\1>


Can anyone help me on this

If someone has more better option to do it

Many Thanks
0
Comment
Question by:tia_kamakshi
  • 4
  • 4
8 Comments
 
LVL 9

Expert Comment

by:bluebelldiscovery
ID: 23700074
You have to place all the java code in this directory
com\lightspeedleader\directorywatcher\*.java


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

Author Comment

by:tia_kamakshi
ID: 23700085
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
0
 
LVL 9

Expert Comment

by:bluebelldiscovery
ID: 23700086
The downloaded zip file (directorywatcher.zip)
only contain path directorywatcher\

therefore you have to manually create
com\lightspeedleader\
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tia_kamakshi
ID: 23700088
Please see my comments above..

Looks we both have posted comments at same time
0
 
LVL 9

Expert Comment

by:bluebelldiscovery
ID: 23700122
I have remove the line
  package com.lightspeedleader.directorywatcher;
from all java files it work for me.

You can download my test file from
http://www.bluebelldiscovery.com/download/directorywatcher/directorywatcher_wo_package.zip
0
 
LVL 9

Accepted Solution

by:
bluebelldiscovery earned 2000 total points
ID: 23700135
Or you can download the correctly zipped file
com\lightspeedleader\directorywatcher\*.java

from
http://www.bluebelldiscovery.com/download/directorywatcher/directorywatcher_w_package.zip

Both solution work for me.
0
 

Author Closing Comment

by:tia_kamakshi
ID: 31549574
Many Thanks It works great
0
 

Author Comment

by:tia_kamakshi
ID: 23700358
HI,

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

Many Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

578 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