Home All Groups Group Topic Archive Search About

difference in Filestream + StreamWriter and just StreamWriter

Author
1 Aug 2006 4:51 PM
iwdu15
hi...just a quick question. what are the differences in using a FileStream
and StreamWriter opposed to just a StreamWriter.....for instance

Dim fs as New FileStream("C:\Test.txt",...)
Dim sw As New StreamWriter(fs)

sw.WriteLine("Stuff")

sw.Flush()
sw.Close()

fs.Close()


and

Dim sw As New StreamWriter("C:\Text.txt")

sw.WriteLine("Stuff")

sw.Flush()
sw.Close()


like obviously memory is different since in the first one there are 2
objects created and only one in the second....but what other significant
differences are there? should i use one way or another? thanks
--
-iwdu15

Author
2 Aug 2006 12:40 PM
Phill W.
iwdu15 wrote:
> hi...just a quick question. what are the differences in using a FileStream
> and StreamWriter opposed to just a StreamWriter.....for instance

Not sure about the Writer, but a notable difference with the
StreamReader that you might want to bear in mind.

    sr = New StreamReader( "file" )

takes a /lock/ on the target file.  processes attempting to append data
to the file will be blocked from doing so.

    fs = New FileStream( "file", ... )
    sr = New StreamReader( fs )

on the other hand, does not, allowing other processes to write to the
file unhindered.

HTH,
    Phill  W.