Copy a file : File Copy : File Directory Stream C# Examples


C# Examples » File Directory Stream » File Copy »

 

Copy a file









    
using  System;  
using  System.IO;    
  
class  MainClass  {  
    public  static  void  Main(string[]  args)  {  
        int  i;  
        FileStream  fin;  
        FileStream  fout;  
  
        try  {  
            fin  =  new  FileStream("inputFile.txt",  FileMode.Open);  
        }  catch(FileNotFoundException  exc)  {  
            Console.WriteLine(exc.Message  +  "\nInput  File  Not  Found");  
            return;  
        }  
  
        try  {  
            fout  =  new  FileStream("outputFile.txt",  FileMode.Create);  
        }  catch(IOException  exc)  {  
            Console.WriteLine(exc.Message  +  "\nError  Opening  Output  File");  
            return;  
        }  
  
        try  {  
            do  {  
                i  =  fin.ReadByte();  
                if(i  !=  -1)  
                      fout.WriteByte((byte)i);  
            }  while(i  !=  -1);  
        }  catch(IOException  exc)  {  
            Console.WriteLine(exc.Message  +  "File  Error");  
        }  
  
        fin.Close();  
        fout.Close();  
    }  
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» File Copy