C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




BinaryReading and BinaryWriting


Posted Date: 23 Jan 2008    Resource Type: Code Snippets    Category: C# Syntax

Posted By: Sateesh Kumar Pal       Member Level: Bronze
Rating:     Points: 10



This is the sample code which perform the writing and reading binary values from a source file or write in a file.


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

namespace Binary_RW
{
class Program
{
static void Main(string[] args)
{
BinaryWriter Dataout;
BinaryReader din;
int i = 11;
double d = 7.9;
bool b = true;
try
{
Dataout = new BinaryWriter(new FileStream("C:\\Satish\\binary.txt", FileMode.Create));
}
catch (IOException e)
{
Console.WriteLine(e.Message + "\n file con not open");
}
try
{
Console.WriteLine("Writing" + i);
Dataout.Write(i);
Console.WriteLine("Writing" + d);
Dataout.Write(d);
Console.WriteLine("Writing" + b);
Dataout.Write(b);
}
catch (IOException e)
{
Console.WriteLine(e.Message + "\n Write error");
}
Dataout.Close();
Console.WriteLine();
//now read them back
try
{
din = new BinaryReader(new FileStream("C:\\Satish\\binary.txt", FileMode.Open));
}
catch (IOException e)
{
Console.WriteLine(e.Message + "\n file cont open");
return;
}
try
{
i = din.ReadInt32();
Console.WriteLine("REading" + i);
d = din.ReadDouble();
Console.WriteLine("REading" + d);
b = din.ReadBoolean();
Console.WriteLine("REading" + b);
}
catch (IOException e)
{
Console.WriteLine(e.Message + "read error");
}
din.Close();
Console.ReadLine();
}
}
}








Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: File uploading in c#
Previous Resource: Grid View data to Excel
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use