PC Review


Reply
Thread Tools Rate Thread

difference in Filestream + StreamWriter and just StreamWriter

 
 
=?Utf-8?B?aXdkdTE1?=
Guest
Posts: n/a
 
      1st Aug 2006
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
 
Reply With Quote
 
 
 
 
Phill W.
Guest
Posts: n/a
 
      2nd Aug 2006
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.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
StreamWriter, FileStream throwing uncatchable NullReferenceException paul.hine@gmail.com Microsoft VB .NET 1 12th Sep 2006 12:49 AM
ASP.NET C# WriteToFile StreamWriter error: 'StreamWriter' could not be found rex64 Microsoft C# .NET 4 15th Jun 2005 03:46 PM
StreamWriter, FileStream, StreamReader - How to know if they are closed McFly Racing Microsoft C# .NET 2 2nd Dec 2004 07:57 AM
Do you need to close FileStream AND StreamWriter? Dan Microsoft C# .NET 4 22nd Sep 2004 03:45 PM
About FileStream and StreamWriter!? Viorel Microsoft Dot NET 1 20th Jul 2003 09:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:54 PM.