In Brief

This chapter discussed how to work with streams in C#, including these topics:

  • Streams are objects designed to let you handle data transfer. There are many stream classes available, such as FileStream , StreamWriter and StreamReader , NetworkStream , and others.

  • Buffered streams can be created with the BufferedStream class. (If you use a stream like FileStream , you're responsible for setting up your own data buffers.)

  • Binary files can be handled with the FileStream class's Read and Write methods .

  • Text files can be handled with the StreamReader and StreamWriter classes, which support the WriteLine and ReadLine methods, respectively. Unlike the standard Write and Read methods, WriteLine and ReadLine are line-oriented.

  • The .NET Framework supports asynchronous streaming I/O with the BeginRead and BeginWrite methods of the Stream class. You can call BeginRead to read a bufferfull of data, or BeginWrite to write a bufferfull of data, and then continue other work. Your code will be called back when the read or write operation is complete.

  • Network I/O is based on the TcpListener and TcpClient classes, which let you create streams that use the TCP/IP protocol.

  • The HttpWebRequest and HttpWebResponse classes enable you to work directly with HTTP streams on the Internet, sending requests from Web servers and reading their responses.

  • When you serialize an object, you store that object, whether to disk or across assembly boundaries. You can pass a BinaryFormatter object a stream to serialize objects.

  • Isolated storage enables you to store application data in a configuration file, so you can avoid using the Registry. You use the IsolatedStorageFileStream class to support isolated storage.



Microsoft Visual C#. NET 2003 Kick Start
Microsoft Visual C#.NET 2003 Kick Start
ISBN: 0672325470
EAN: 2147483647
Year: 2002
Pages: 181

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