advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Do you miss classic VB's file I/O statements? Did this article help show how VB.NET replaces those statements? Do you think the VB.NET versions are more or less powerful than classic VB? Let us know in the vb.dotnet.discussion or vb.dotnet.technical discussion groups.
Partners & Affiliates
advertisement
advertisement
Average Rating: 4.3/5 | Rate this item | 12 users have rated this item.
 Print Print
 
Take Advantage of Streams and Formatters in VB.NET
.NET File I/O operations use Stream and Formatter classes that abstract many tasks you had to code manually in classic VB.  

advertisement
When you first start learning VB.NET, one of the first things you may notice is the absence of "traditional" file I/O support in .NET. Microsoft has replaced the classic IO operations by stream operations. A stream is a simple concept that originated in the Unix world.

You can think of stream as a channel through which data flows from your application to a sequential data store (such as a file, a string, a byte array, or another stream), or vice versa. To understand why the traditional file I/O operations were replaced by streams, you must consider that not all data reside in files. Modern applications acquire data from many different data stores, including files, in-memory buffers and the Internet. The stream analogy enables applications to access all these data stores with the same programming model. There's no need to learn how to use Sockets to access a file on a remote Web server. You can establish a stream between your application and a remote resource and read the bytes as the server sends them.

A stream encapsulates all the operations you can perform against a data store. The big advantage is that after you learn how to deal with streams for one data source, you can apply the same techniques to widely differing data sources. This article primarily focuses on using streams with files, but you'll see a few examples of using streams with other data stores, such as resources on a remote server, toward the end of this article.

Types of Streams
The Stream class is abstract; you can't declare a new instance of type Stream in your code. There are five classes in the .NET Framework that derive from the Stream class. These are:

  • FileStream. Supports sequential and random access to files
  • MemoryStream. Supports sequential and random access to memory buffers
  • NetworkStream. Supports sequential access to Internet resources. The NetworkStream resides in the System.Net.Sockets namespace.
  • CryptoStream. Supports data encryption and decryption. The CryptoStream resides in the System.Security.Cryptography namespace.
  • BufferedStream. Supports buffered access to stream that do not support buffering on their own
Not all streams support exactly the same operations. A stream for reading a local file, for example, can report the length of the file and the current position in the file, with the Length and Position properties, respectively. You can jump to any location in the file with the Seek method. In contrast, a stream for reading a remote file doesn't support those features. But the stream classes help you differentiate Streams programmatically, by providing CanSeek, CanRead and CanWrite properties. Despite some data-store-dependent differences, the basic methods of all Stream classes let you write data to or read data from the underlying data store.

  Next Page: Using the FileStream Class
Page 1: Types of StreamsPage 4: Object Serialization
Page 2: Using the FileStream ClassPage 5: Common File I/O Scenarios
Page 3: More Flexible I/O OperationsPage 6: Downloading Internet Resources
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES