S
SurturZ
OK maybe I'm missing something obvious.
Look at the following code:
Using fs As New
FileStream(My.Computer.FileSystem.SpecialDirectories.Desktop & "\junk.txt",
FileMode.Create, FileAccess.Write, FileShare.ReadWrite)
Using sw As New StreamWriter(fs, System.Text.Encoding.ASCII)
sw.WriteLine("abc")
sw.WriteLine("def")
sw.WriteLine("ghi")
End Using
Using bw As New BinaryWriter(fs) 'throws an error right here
bw.Write(CByte(&H4A)) 'J
bw.Write(CByte(&H4B)) 'K
bw.Write(CByte(&H4C)) 'L
bw.Write(CByte(&HA)) '[CR]
bw.Write(CByte(&HD)) '[LF]
bw.Write(CByte(&H4D)) 'J
bw.Write(CByte(&H4E)) 'K
bw.Write(CByte(&H4F)) 'L
bw.Write(CByte(&HA)) '[CR]
bw.Write(CByte(&HD)) '[LF]
End Using
End Using
It crashes on the line indicated with a "Stream not writeable" exception.
I'm assuming the StreamWriter is closing the underlying FileStream when it
is disposed. Where's the Filestream.Open command??
Look at the following code:
Using fs As New
FileStream(My.Computer.FileSystem.SpecialDirectories.Desktop & "\junk.txt",
FileMode.Create, FileAccess.Write, FileShare.ReadWrite)
Using sw As New StreamWriter(fs, System.Text.Encoding.ASCII)
sw.WriteLine("abc")
sw.WriteLine("def")
sw.WriteLine("ghi")
End Using
Using bw As New BinaryWriter(fs) 'throws an error right here
bw.Write(CByte(&H4A)) 'J
bw.Write(CByte(&H4B)) 'K
bw.Write(CByte(&H4C)) 'L
bw.Write(CByte(&HA)) '[CR]
bw.Write(CByte(&HD)) '[LF]
bw.Write(CByte(&H4D)) 'J
bw.Write(CByte(&H4E)) 'K
bw.Write(CByte(&H4F)) 'L
bw.Write(CByte(&HA)) '[CR]
bw.Write(CByte(&HD)) '[LF]
End Using
End Using
It crashes on the line indicated with a "Stream not writeable" exception.
I'm assuming the StreamWriter is closing the underlying FileStream when it
is disposed. Where's the Filestream.Open command??