G
Guest
I have the need to write a byte of information to a specific location in a
text file.
eg. the file looks something like this.
FYYNN
Line 1
Line 2
<eof>
The first character is a flag indicating the file has changed and the 2 -
4th characters are flags indicating the line of data that has changed ie Y or
N.
What I need to do is set the last four characters on the first line and then
write a line coresponding to each of the 'Y' flags. Finally and it must be
the last thing I do is set the first character on the first line to a flag
which is used by a second application to initate an action.
I hope this makes sense.
initial myfile.txt
WNNNN
<eof>
Below is a sub that I am using to try and update the first flag.
Sub WriteFile()
Dim fs As New System.IO.FileStream("C:\myFile.txt",
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite)
Dim w As New System.IO.BinaryWriter(fs)
fs.Seek(1, IO.SeekOrigin.Begin)
w.Seek(1, SeekOrigin.Begin)
w.Write(CChar("X"))
End Sub 'Main
Resulting myfile.txt
ïX¿WNNNN
<eof>
text file.
eg. the file looks something like this.
FYYNN
Line 1
Line 2
<eof>
The first character is a flag indicating the file has changed and the 2 -
4th characters are flags indicating the line of data that has changed ie Y or
N.
What I need to do is set the last four characters on the first line and then
write a line coresponding to each of the 'Y' flags. Finally and it must be
the last thing I do is set the first character on the first line to a flag
which is used by a second application to initate an action.
I hope this makes sense.
initial myfile.txt
WNNNN
<eof>
Below is a sub that I am using to try and update the first flag.
Sub WriteFile()
Dim fs As New System.IO.FileStream("C:\myFile.txt",
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite)
Dim w As New System.IO.BinaryWriter(fs)
fs.Seek(1, IO.SeekOrigin.Begin)
w.Seek(1, SeekOrigin.Begin)
w.Write(CChar("X"))
End Sub 'Main
Resulting myfile.txt
ïX¿WNNNN
<eof>