Write byte array to a file

image_pdfimage_print
   
 


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

class Program {
    static void Main(string[] args) {
        byte[] byData;
        char[] charData;

        try {
            FileStream aFile = new FileStream("Temp.txt", FileMode.Create);
            charData = "www.kutayzorlu.com/java2s/com".ToCharArray();
            byData = new byte[charData.Length];
            Encoder e = Encoding.UTF8.GetEncoder();
            e.GetBytes(charData, 0, charData.Length, byData, 0, true);

            aFile.Seek(0, SeekOrigin.Begin);
            aFile.Write(byData, 0, byData.Length);
        } catch (IOException ex) {
            Console.WriteLine(ex.ToString());
            return;
        }
    }
}

    


This entry was posted in File Stream. Bookmark the permalink.