IntelliJ Java IDE
The moose likes I/O and Streams and the fly likes Detect new file in a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Detect new file in a directory" Watch "Detect new file in a directory" New topic
Author

Detect new file in a directory

Roy Cantos
Ranch Hand

Joined: Feb 22, 2002
Posts: 38
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

Joined: Nov 02, 2000
Posts: 512
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


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Matt Siegel
Ranch Hand

Joined: Jul 18, 2000
Posts: 55
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
 
 
subject: Detect new file in a directory
 
Threads others viewed
getting a filename
Detecting EOF?
Checking for EOF
Detect new file in a directory
java redirection
developer file tools