• Post Reply Bookmark Topic Watch Topic
  • New Topic

Detect new file in a directory

 
Roy Cantos
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Is there a way that java can detect a new file, or existing API that we can use.

Thanks,
Roy
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to know if the was created or not then use the exists() method off of the File class. If you are talking about the creation date, I'm not sure where to find that.
-Dale
 
Matt Siegel
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you mean that you want to check when a new file is put into a directory. I had to do something like this once. Here's what I did:
Using java.io.File.listFiles() I got an array of files in the directory. And then after a period of time, something like 5 secs which is configurable, I used some set operations to determine if any new files were put in the directory.
Unfortunately I do not have any of the code anymore, but here's something:

HTH,
Matt
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!