Read text file which is still updated

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yaniv

    #1

    Read text file which is still updated

    Hi

    I'm new in VB.NET.
    I wrote an application which opens a text file and read it all lines
    untill the EOF
    this file is open for read only and for sharing asllowed.
    every 5 seconds another applications write another line to this file
    at the end and I'm trying to read those new lines from my
    applications. the problem is that the EOF function returns TRUE even
    though a new lines added to this file.
    what can I do?

    I open the file using the function:
    FileOpen(1, File, OpenMode.Input, OpenAccess.Read , OpenShare.Share d)

    I read line using the function:
    Linet = LineInput(1)

    I check EOF with the function:
    EOF(1)

    Do I need to use diffrent functions for open and read that file?

    Thanks for the help...

  • lord.zoltar@gmail.com

    #2
    Re: Read text file which is still updated


    Yaniv wrote:
    Hi
    >
    I'm new in VB.NET.
    I wrote an application which opens a text file and read it all lines
    untill the EOF
    this file is open for read only and for sharing asllowed.
    every 5 seconds another applications write another line to this file
    at the end and I'm trying to read those new lines from my
    applications. the problem is that the EOF function returns TRUE even
    though a new lines added to this file.
    what can I do?
    >
    I open the file using the function:
    FileOpen(1, File, OpenMode.Input, OpenAccess.Read , OpenShare.Share d)
    >
    I read line using the function:
    Linet = LineInput(1)
    >
    I check EOF with the function:
    EOF(1)
    >
    Do I need to use diffrent functions for open and read that file?
    >
    Thanks for the help...
    Maybe close the file after reading, then reopen it after 5 seconds.
    It's simple, but that would be a lot of file opening and closing...
    Instead, maybe have a bookmark variable keep track of the number of
    lines you have read. Then, after 5 seconds, seek back to the bookmark
    (there's a procedure that lets you set the position in the file
    stream) and start reading again. You'd have to change your reading
    loop a bit.

    Comment

    • Yaniv

      #3
      Re: Read text file which is still updated

      Thanks.

      Could you please tell me which function does that ?
      Is there a code sample anywhere in the internet for this?

      lord.zoltar@gma il.com כתב:
      Yaniv wrote:
      Hi

      I'm new in VB.NET.
      I wrote an application which opens a text file and read it all lines
      untill the EOF
      this file is open for read only and for sharing asllowed.
      every 5 seconds another applications write another line to this file
      at the end and I'm trying to read those new lines from my
      applications. the problem is that the EOF function returns TRUE even
      though a new lines added to this file.
      what can I do?

      I open the file using the function:
      FileOpen(1, File, OpenMode.Input, OpenAccess.Read , OpenShare.Share d)

      I read line using the function:
      Linet = LineInput(1)

      I check EOF with the function:
      EOF(1)

      Do I need to use diffrent functions for open and read that file?

      Thanks for the help...
      >
      Maybe close the file after reading, then reopen it after 5 seconds.
      It's simple, but that would be a lot of file opening and closing...
      Instead, maybe have a bookmark variable keep track of the number of
      lines you have read. Then, after 5 seconds, seek back to the bookmark
      (there's a procedure that lets you set the position in the file
      stream) and start reading again. You'd have to change your reading
      loop a bit.

      Comment

      • =?ISO-8859-1?Q?G=F6ran_Andersson?=

        #4
        Re: Read text file which is still updated

        Yaniv wrote:
        Hi
        >
        I'm new in VB.NET.
        I wrote an application which opens a text file and read it all lines
        untill the EOF
        this file is open for read only and for sharing asllowed.
        every 5 seconds another applications write another line to this file
        at the end and I'm trying to read those new lines from my
        applications. the problem is that the EOF function returns TRUE even
        though a new lines added to this file.
        what can I do?
        >
        I open the file using the function:
        FileOpen(1, File, OpenMode.Input, OpenAccess.Read , OpenShare.Share d)
        >
        I read line using the function:
        Linet = LineInput(1)
        >
        I check EOF with the function:
        EOF(1)
        >
        Do I need to use diffrent functions for open and read that file?
        >
        Thanks for the help...
        >
        I believe that you have to close the file and open it again to get a
        file handle with the new file size.

        If you only want to read the added lines, you can periodically check for
        a change in the file size. When it changes you can open the file as a
        binary file, seek to the previos file end and read the remaining bytes.
        Then you can use the Encoding.UTF8 object to decode the bytes into a string.

        However, reading a file that is being written to is a bit shaky. If
        possible, perhaps you should consider an alternative way of storing the
        information, like for example a database table. A database is better
        equipped to handle simultaneous reading and writing of data than the
        file system is.

        --
        Göran Andersson
        _____
        Göran Anderssons privata hemsida.

        Comment

        Working...