If you are wanting to catch files added or removed from
out side your program then you'll have to start a thread
to monitor the contents of the directory.
public class monitor extends Thread
{
public String list[];
public String directory;
public monitor(String direc)
{
directory=direc;
File f=new File(direc);
list=File.list();
}
public void run()
{
File f= new File(directory);
String[] listing=f.list();
if(listing.length != list.length)
{
//event
}else {
for(int i=0;i<listing.length;i++)
if(!(listing.equals(list);
//event
}
try{
sleep(3000);//sleeps 3 seconds
}catch(InterruptedException ie)
{}
}
}
However bear in mind that this will not catch changes to
subdirectories. Also you can get into trouble with
sym-links since it will see sym-links the same as files
ie people will be able to fool it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.