Copy a file by copying byte by byte in CSharp

Description

The following code shows how to copy a file by copying byte by byte.

Example


 //  w ww .  ja  v  a  2s . c  o  m
using System; 
using System.IO;  
 
class MainClass { 
  public static void Main(string[] args) { 
    int i; 
    FileStream fin = new FileStream("inputFile.txt", FileMode.Open); 
    FileStream fout = new FileStream("outputFile.txt", FileMode.Create); 
    do { 
        i = fin.ReadByte(); 
        if(i != -1) 
           fout.WriteByte((byte)i); 
    } while(i != -1); 
 
    fin.Close(); 
    fout.Close(); 
  } 
}




















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