Introduction to Streams and Files in C#

This article introduces and describes streams and their properties, version information, methods, syntax and so on with examples. In this article I also describe the file class and directory class.

Stream | Introduction

We can perform two operations on a file:

  • Move data into it.
  • Move data out of it

These operations can be performed across the network, over the internet or anywhere else depending on you. But the data you do process must be streamed.

Stream Class

Stream Class

Stream Data

Stream data can be stored or forwarded over the network via these three backing stores or we can call it backup of the streamed data.
These backing stores are:
  • File
  • Network
  • Internet

Stream Data 

Properties | Streams
  • A stream can be:

       1. Readable
       2. Writeable
       3. Both
     
  • Streams can also be seekable or we can say that some types of streams can support a current position that can be queried or modified.
  • All streams derive from an abstract base class:
    System.IO.Stream

Properties 

Stream | Hierarchy
 
Stream

Syntax

Here is some syntax for the Stream class:
 
Syntax

Methods

There are several methods used in the Stream class, some of them am presented here. For more details you can go to msdn.channel9.
 
Methods

Version Information
 
Version Information

Inheritance Hierarchy

You can also go through these:
 
Inheritance Hierarchy

Example
 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 

namespace Hello_Word

{

   class Struct

    {

        public struct Point

        {

            private int xCord;

            private int yCord;

 

            public Point(int x, int y)

            {

                xCord = x;

                yCord = y;

            }

 

            public int x

            {

                get { return xCord; }

                set { xCord = value; }

            }

 

            public int y

            {

                get { return xCord; }

                set { xCord = value; }

           }

     }

}

File Classes

The System.IO namespace provides functionality for file classes.

Working with Classes

There are generally 3 types of file classes provided by the System.IO namespace in C# and they are as follows:

  • File
  • FileInfo
  • FileStream

Working with Classes

Directory Classes

  • The System.IO namespace also provides directory classes along with file classes.
  • There are the following 2 types of these classes:

       1. Directory
       2. DirectoryInfo

Directory Classes


Similar Articles