Copy a file chunk by chunk in CSharp

Description

The following code shows how to copy a file chunk by chunk.

Example


         //from ww  w  . ja  va 2s .  c om

using System;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Threading;

public class MainClass
{
    public static void Main()
    {
        using (Stream from = new FileStream("main.cs", FileMode.Open))
        using (Stream to = new FileStream("c:\\test2.txt", FileMode.OpenOrCreate))
        {
            int readCount;
            byte[] buffer = new byte[1024];
            while ((readCount = from.Read(buffer, 0, 1024)) != 0)
            {
                to.Write(buffer, 0, readCount);
                Console.WriteLine("copying");
            }
        }
    }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip