C#
  Home arrow C# arrow C# FileStream Explained
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

C# FileStream Explained
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 28
    2007-01-31

    Table of Contents:
  • C# FileStream Explained
  • The FileStream Class
  • Writing to the file using FileStream methods
  • Reading from the file using FileStream methods
  • Use the Seek() method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    C# FileStream Explained


    (Page 1 of 5 )

    In the last two articles, we talked about creating, moving and copying files and directories. Today we are going to discuss writing to and reading from files using the available classes in the namespace System.IO.

    We have many classes in this namespace like Stream, FileStream, StreamReader and StreamWriter, along with other classes that are used to read from and write to files. Today we are going to discuss the difference between those classes and how we can use them. The best way to understand the concepts of this topic is by practice, so as usual you are going to see a lot of examples.

    Do you know what a stream is? No? Okay, a stream is a general representation of bytes. We use a stream-based class to read bytes from sources like files, memory or even network locations. We also use it to write bytes to those sources. So we can look at a stream as a bridge between a source like a file and your program to transfer data in its byte format. The .NET Framework provides the FileStream class which is used for read/write operations (as we said, in byte format) between your program and a file. The .NET Framework also provides the MemoryStream class, which is used for read/write operations between your program and memory.

    Note that FileStream and MemoryStream classes are derived from the Stream abstract base-class. The Stream class has methods like Read(), ReadByte(), Write() and WriteByte() which are overridden in derived classes (like the FileStream and MemoryStream classes) to provide an implementation that's specific to the source. This makes sense because the implementation of the method WriteByte() of the FileStream class differs from the implementation of MemoryStream.WriteByte(); the first one writes a byte to a file and the latter one writes a byte to the memory.

    Let's begin with the FileStream class so you can understand what we are talking about here.

    More C# Articles
    More By Michael Youssef


       · Do you know what a FileStream instance is? No? Ok read the article :)
       · I just can't stop reading your articles. Can't you write a book about C# please? I'm...
       · Hi Marie,I wish I can write a book but this needs time and there are many...
       · Hi, This is nice to study ur article.Your explanation is very good.If u...
       · I found this article very useful to get to know about the File Streams in a quick...
       · Hello Sarav,What exactly the topics you would like me to write about?Have you...
       · I wonder if you can help me with this.DBAccessor class is using FileStream obj...
       · hey,I need to know how to implement the c++ ignore function for filestreams in c#,...
     

    C# ARTICLES

    - Coding a CRC-Generating Algorithm in C
    - Cyclic Redundancy Check
    - Handling Methods and Functions
    - Destroying Objects in C#
    - Creating Objects in C-Sharp
    - Classes and Objects
    - Programming Languages: Managed versus Native
    - LINQ-to-MySQL with DbLinq in C#
    - Working with Dates and Times in C#
    - Generics, Dictionaries, and More
    - More About Generics
    - Working with C# Collections
    - Generics
    - C# and XML
    - Pointers and Arrays in C#





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek