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 / General / August 2006

Tip: Looking for answers? Try searching our database.

Ensuring that a file is not written to

Thread view: 
varlagas@yahoo.com - 01 Aug 2006 15:06 GMT
Dear all,

I wonder if anyone of you guys out there could help me out with this:

I want to read a file, but only want to do that when another process
that is creating it is done creating it. Say it is an (external)
process A that creates the file and my process B that reads the file. I
want to somehow verify that when an attempt is made by B to read that
particular file in the file system, the file is not currently being
written to by process A.

A ----> writes ---> file <--- reads ---- B

Is there any way to do this in Java?

Many thanks!!!

Panagiotis.
Eric Sosman - 01 Aug 2006 16:01 GMT
varlagas@yahoo.com wrote On 08/01/06 10:06,:
> Dear all,
>
[quoted text clipped - 10 lines]
>
> Is there any way to do this in Java?

   Not that I know of.  One technique that's often used
is to have A write to "output.tmp", say, and rename it to
"output.dat" when it has finished all its writing.  That
way, B cannot even find the "output.dat" file while A is
still writing it.

Signature

Eric.Sosman@sun.com

tiewknvc9 - 01 Aug 2006 16:27 GMT
how about this.

Make another file called flag.txt
set the text of flag.txt text to "1" when the program is creating it,
then set the flag.txt text to "0" when it is done creating it.

Before process B reads the file, check its associated flag.

you can create many flag.txt files, you could simply use the
strNameOfTheFile + "flag.txt" as the unique flag.txt documents per
file.

let me know how it goes for you.

> varlagas@yahoo.com wrote On 08/01/06 10:06,:
> > Dear all,
[quoted text clipped - 17 lines]
> way, B cannot even find the "output.dat" file while A is
> still writing it.
EJP - 02 Aug 2006 02:03 GMT
> how about this.
>
[quoted text clipped - 32 lines]
>>way, B cannot even find the "output.dat" file while A is
>>still writing it.

I prefer the renaming method, but if you do the above you don't need the
0/1 contents of 'flag.txt', you can just check for its presence or absence.


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.