Hi All:
I am fairly new to Java. I have a problem at hand which I would like
to solve using the Java approach.
Basically, I would like to monitor a specific directory (with
subdirectories) in one of the servers in a network. When a file has
been added to this specific directory, I would like to notify another
PC in the same network, so that a specific application residing in
that particular PC can take the cue and do some processing.
May I know can Java be used to achieve this objective?
Thank you very much.
klynn47@comcast.net - 02 Feb 2005 16:58 GMT
You can get information about the files in a directory with
java.io.File. There are various approaches you could use to solve your
problem. Are you using Windows or UNIX?
Ishmael Rufus - 02 Feb 2005 18:09 GMT
psst. ... timers/threads...
Matt Humphrey - 02 Feb 2005 20:29 GMT
> Hi All:
>
[quoted text clipped - 9 lines]
> May I know can Java be used to achieve this objective?
> Thank you very much.
As klynn47 pointed out you can use java.io.File operations to monitor the
contents of a directory. However, you should know that there is no real way
to know that a file has been fully added to a directory. If a 100 MB file
is being added, the file will appear with some part (but not necessarily
all) of its contents. The file size will grow until the file is fully
present. Unless you know the size in advance you need to be willing to
guess that copying is finished when the size stops changing. If you have
control over the program that is adding the file, an effective technique is
to get that program to write the file to a temp file first and when the
writing is complete to rename it to the final name. Renaming a file is
typically an atomic operation whereas copying is not.
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/