Ensuring that a file is not written to

Discussion in 'Java' started by varlagas@yahoo.com, Aug 1, 2006.

  1. Guest

    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.
     
    , Aug 1, 2006
    #1
    1. Advertising

  2. Eric Sosman Guest

    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.

    --
     
    Eric Sosman, Aug 1, 2006
    #2
    1. Advertising

  3. tiewknvc9 Guest

    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:
    > 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.
    >
    > --
    >
     
    tiewknvc9, Aug 1, 2006
    #3
  4. EJP Guest

    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:
    >
    >> 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.
     
    EJP, Aug 2, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD
    Replies:
    1
    Views:
    570
    reaway lee
    Aug 24, 2003
  2. David
    Replies:
    0
    Views:
    329
    David
    May 2, 2004
  3. Simon
    Replies:
    3
    Views:
    841
    Simon Harvey
    May 26, 2004
  4. Peter Hardy

    Ensuring users have provided valid html

    Peter Hardy, Dec 29, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    332
    Peter Hardy
    Dec 29, 2004
  5. KaiWen
    Replies:
    102
    Views:
    2,777
    Jorgen Grahn
    Sep 15, 2011
Loading...

Share This Page