How to convert your file into binary form?

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 

namespace string_to_binary

{

    class Program

    {

        static void Main(string[] args)

        {

            FileStream fs = new FileStream(@"E:\output.txt", FileMode.Create);

            BinaryWriter w = new BinaryWriter(fs);

            for (int i = 0; i < 100; i++)

                w.Write((int)i);

            w.Close();

            fs.Close();

 

            fs = new FileStream(@"E:\output.txt", FileMode.Open, FileAccess.Read);

            BinaryReader r = new BinaryReader(fs);

            for (int i = 0; i < 100; i++)

                Console.WriteLine(r.ReadInt32());

            r.Close();

            fs.Close();

            Console.WriteLine(Console.Read());

        }

    }

}

Ebook Download
View all
Learn
View all