Results 1 to 4 of 4

Thread: Open file for jus reading

  1. #1
    Join Date
    Jun 2005
    Posts
    762

    Default Open file for jus reading

    is it possible for a file to be open in only a read mode so that it can be edited???

    for example i created a program that keeps on reading from a file but when i try to edit the file i get an error [ i am assuming that it is bcuz the program is using the file so it has been lock bcuz when i close teh program i can save it]

    this is what i did

    File.OpenText(path); this is in a thread that keeps on looping and captures the data

    should i have used file.openText ????????????
    Processor: Intel(R) Xeon(R) E5520 @2.27GHz 2.26GHz
    Memory(RAM): 4GB
    HD: 600GB
    RAID: 1

  2. #2
    Join Date
    Dec 2004
    Posts
    1,183

    Default

    what you shoul do is close it back on every loop and then reopen it on entering back the loop and searching for end-of-file. I know in C, you cant do two consecutive operations on a file, unless you close the file and reopen it first.
    'If we're supposed to work in Hex, why have we only got A fingers?'

    Follow Me: @psybuck2002us

  3. #3
    Join Date
    Sep 2004
    Posts
    639

    Default

    Quote Originally Posted by keroed1
    is it possible for a file to be open in only a read mode so that it can be edited???
    Psybuck2002us's suggestion will probably fix your problem. I suppose you could also try using a FileStream object which gives you more granular control over things like mode, access and sharing when opening a file.

    Quote Originally Posted by keroed1
    i created a program that keeps on reading from a file ... this is in a thread that keeps on looping and captures the data
    Just out of curiosity are you using the FileSystemWatcher to monitor file changes or do you just have it constantly polling the text file? Is this related to your previous posts about connecting to a serial device?

  4. #4
    Join Date
    Jun 2005
    Posts
    762

    Default

    yes it was related to my previous post about a serial device and i found that through file streaming i was able to access the text file as a stream and this work perfectly,

    but then i started to think about the volume of data that would be in this text file and i found that looping through a large text file may start to affect program that is running using asystem thread

    so i decided to instead let a program write to a database and then i can connect to that database every 2secs read record and then delete it after i have read the record, and then do my modification of the data that was colected.

    thus the use of the database instead of a text file allowed me the flexibilty for my three diffewrrent programs to eb connecting to the same data with two to doing both read/write and one jus reading................and the files size to be drastically less so thats pretty much solved at the moment
    Processor: Intel(R) Xeon(R) E5520 @2.27GHz 2.26GHz
    Memory(RAM): 4GB
    HD: 600GB
    RAID: 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •