Create a FileStream for the BufferedStream. : BufferedStream « File Stream « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » File Stream » BufferedStreamScreenshots 
Create a FileStream for the BufferedStream.



using System;
using System.IO;

class BufStreamApp
{
    static void Main(string[] args)
    {
        FileStream fs = new FileStream("Hoo.txt",FileMode.Create, FileAccess.ReadWrite);
        BufferedStream bs = new BufferedStream(fs);
        Console.WriteLine("Length: {0}\tPosition: {1}",bs.Length, bs.Position);
   
        for (int i = 0; i < 64; i++)
        {
            bs.WriteByte((byte)i);
        }
        Console.WriteLine("Length: {0}\tPosition: {1}", bs.Length, bs.Position);
        byte[] ba = new byte[bs.Length];
        bs.Position = 0;
        bs.Read(ba, 0(int)bs.Length);
        foreach (byte b in ba)
        {
            Console.Write("{0,-3}", b);
        }
   
        string s = "Foo";
        for (int i = 0; i < 3; i++)
        {
            bs.WriteByte((byte)s[i]);
        }
        Console.WriteLine("\nLength: {0}\tPosition: {1}\t",bs.Length, bs.Position);
   
        for (int i = 0; i < (256-67)+1; i++)
        {
            bs.WriteByte((byte)i);
        }
        Console.WriteLine("\nLength: {0}\tPosition: {1}\t", bs.Length, bs.Position);
   
        bs.Close();
    }
}

       
Related examples in the same category
1.illustrates use of BufferedStreams
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.