Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Ensuring that a file is not written to

Reply
Thread Tools

Ensuring that a file is not written to

 
 
varlagas@yahoo.com
Guest
Posts: n/a
 
      08-01-2006
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.

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-01-2006


http://www.velocityreviews.com/forums/(E-Mail Removed) wrote On 08/01/06 10:06,:
> 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?


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.

--
(E-Mail Removed)

 
Reply With Quote
 
 
 
 
tiewknvc9
Guest
Posts: n/a
 
      08-01-2006
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.



Eric Sosman wrote:
> (E-Mail Removed) wrote On 08/01/06 10:06,:
> > 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?

>
> 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.
>
> --
> (E-Mail Removed)


 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      08-02-2006
tiewknvc9 wrote:
> 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.
>
>
>
> Eric Sosman wrote:
>
>>(E-Mail Removed) wrote On 08/01/06 10:06,:
>>
>>>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?

>>
>> 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.


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Generally, are the programs written by C++ slower than written by C10% ? KaiWen C++ 102 09-14-2011 11:12 PM
Ensuring Security at HotSpots question Bill Wireless Networking 7 11-03-2004 11:29 AM
ensuring that all declared controls have been drawn David ASP .Net 0 05-02-2004 09:46 AM
Re: Can a usercontrol written in C# be used in Web Forms that is written in VB.Net? Steve C. Orr, MCSD ASP .Net 1 08-24-2003 12:06 AM



Advertisments