difference in Filestream + StreamWriter and just StreamWriter

G

Guest

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
 
P

Phill W.

iwdu15 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top