• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1719
  • Last Modified:

FIlewatcher in java

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
tia_kamakshi
Asked:
tia_kamakshi
  • 4
  • 4
1 Solution
 
bluebelldiscoveryCommented:
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
 
tia_kamakshiAuthor Commented:
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
 
bluebelldiscoveryCommented:
The downloaded zip file (directorywatcher.zip)
only contain path directorywatcher\

therefore you have to manually create
com\lightspeedleader\
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
tia_kamakshiAuthor Commented:
Please see my comments above..

Looks we both have posted comments at same time
0
 
bluebelldiscoveryCommented:
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
 
bluebelldiscoveryCommented:
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
 
tia_kamakshiAuthor Commented:
Many Thanks It works great
0
 
tia_kamakshiAuthor Commented:
HI,

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

Many Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now