Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2005

Tip: Looking for answers? Try searching our database.

Directory monitoring using Java

Thread view: 
Tanuki - 02 Feb 2005 16:26 GMT
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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.