Combo Boxes

 

Identifying Read/Write Failures

There are significant differences between StreamReader and StreamWriter. For example, StreamReader has a ReadBlock mechanism that is extremely useful; StreamWriter has no equivalent (but Write may be considered its equivalent since the length of the write buffer is set in the StreamWriter statement; StreamReader has no such buffer size set).

It is also a little strange that, in the case of StreamReader, there is no mention of the size of the read until you reach the ReadBlock() statement. But in StreamWriter the write size is set in the initial StreamWriter construct and nothing need be said about the size in the follow-on statement, Write(). Obviously two different groups of compiler writers fashioned these statements.

Despite having said all of the above, the average programmer should have no problems with file creation, reading, and writing using FileStream, StreamReader, and StreamWriter.

Programmers usually place a source code location in a MessageBox message that indicates when a file is missing or fails to read or write. If you do not place a location in the message and you read and write files in many places in your project, a failure to read/write notice may leave you baffled. So we normally write the message this way:

 MessageBox.Show("F3L222: Cannot find file SpareShort.dta to read."); 

This means the code is located in Form3, line 222. These notices are removed when the project is complete and all is running well. We use the MessageBox as a quasi debug mechanism, as do most other programmers.

 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net