Blog

How to convert your file into binary form?

By Owais Khan Blogs | Files, Directory, IO Sep 21, 2010
How to convert your file into binary form?
Download Files: string to binary.zip

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());

        }

    }

}

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs