Use FileStream to write a file by byte array : File Byte Read Write : File Directory Stream C# Examples


C# Examples » File Directory Stream » File Byte Read Write »

 

Use FileStream to write a file by byte array









    
using  System;
using  System.Windows.Forms;
using  System.IO;

class  MainClass
{
    public  static  void  Main()  
    {
        FileStream  inStream  =  File.OpenRead("C:\\test.txt");
        FileStream  outStream  =  File.OpenWrite("C:\\test.txt"  +  ".bak");
        byte[]  buf  =  new  byte[4096];
        int  bytesRead;

        while  ((bytesRead  =  inStream.Read(buf,  0,  4096))  >  0)
            outStream.Write(buf,  0,  bytesRead);

        outStream.Flush();
        outStream.Close();
        inStream.Close();

    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» File Byte Read Write