Blog

How to convert your file into binary form?

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

        }

    }

}

post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter