|
Streams
Aug 4, 2005 18:21:44 GMT -5
Post by Bill Sun on Aug 4, 2005 18:21:44 GMT -5
Hi,
I'm curious with the new Stream classes. What are the benefits of the StreamWriter and related classes over the old Open file to #n and Print method in when writing to a file?
-Bill
|
|
|
Streams
Aug 5, 2005 14:07:02 GMT -5
Post by Kelly Ethridge on Aug 5, 2005 14:07:02 GMT -5
Hello Bill,
If you are trying to compare VB procedural file manipulations against a FileStream object then there really is no benefit. There is actually less of a benefit because the FileStream only works with Byte arrays. Well, the FileStream isn't limited by the 2gig file size and you can set the file size yourself.
In reality, you can't compare VB IO operations against a FileStream because they are not for the same purpose. A FileStream is simply a concrete implementation of the abstract concept of Stream.
Anything that can write to a Stream can write to a FileStream, MemoryStream, or streams not invented yet, such as for network sockets, serial ports and modems, blue-tooth and such.
This is all about programming with objects, not procedures. Even with the two tools provided with the source code I use a FileWriter to abstract the notion of writing a specific data type to a file without me needing to worry about it. I could have written it all procedurally, but I just don't think that way.
So in essence, the FileStream is not the same as the VB IO routine. It is another Stream that can be written to and read from. The StreamWriter doesn't care where the actual bytes go, just that something accepts them.
The StreamWriter has the benefit of using any kind of encoding of the values being written, then dumping them to a Stream. So you could use the UTF7Encoding to get any data through a 7-bit routing system.
It's impossible to provide serious examples because it will always depend on your problem domain. Saying that VB can write to a file may be nice, but may not have any benefit for someone writing to a database. It just depends on what you are doing and how you like to solve problems.
Kelly
|
|