Click here to Skip to main content
15,877,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i want to convert the binary file to string file.can any body tell me tell me how can i perform this
Posted
Comments
OriginalGriff 4-Mar-11 5:20am    
What kind of data is in your binary file?
How do you need it stored in your text file?
Edit you question, and provide better info!
Albin Abel 4-Mar-11 6:38am    
For what purpose?. Simply base64 string?

1 solution

If you are dealing with simple data types, then you can use BinaryReader and StreamWriter classes.
For example:
C#
using (StreamWriter writer = new StreamWriter(textFileName))
{
    using (BinaryReader reader = new BinaryReader(
        File.Open(binaryFileName, FileMode.Open)))
    {
        //reads an int
        int myInt = reader.ReadInt32();
        //writes it
        writer.WriteLine(myInt);
        //reads a float
        float myFloat = reader.ReadSingle();
        //writes it
        writer.WriteLine(myFloat);
        ...
    }
}



But binary files can contain any kind of data. So it is up to you to read the data properly...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900