convert bin file to text file in c#

Hi,

I need to convert a bin file to txt file in C#. Please show me some example code.

Thanks

Lanac
lanac222Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nayernaguibCommented:
If "bin" refers to a binary file, then you should know that at the storage level, there is no difference between files containing binary data and those containing text; both are stored in binary format. You can open both files in whatever mode you like. The problem is that when you open a binary file for processing in text mode, you get unreadable characters (and possibly the file truncates at the first null character encountered, which is used to specify the End-Of-File for text files). Similarly, when you open a text file in binary access mode, you process the file (read/write) as a stream of bytes, which is inconvenient.

_______________

  Nayer Naguib
0
nayernaguibCommented:
Using sample code listed on the following page, you can try opening and manipulating both types of files (binary/text) in both modes:

  http://www.ondotnet.com/pub/a/dotnet/2002/08/05/io.html?page=5

_______________

  Nayer Naguib
0
lanac222Author Commented:
but i'd like to convert the binary data to man readable text.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

nayernaguibCommented:
Usually, binary files do not contain readable text. Try opening some MP3 or AVI file using Notepad and take a look at its contents!
If you are sure that some file contains readable text (even if the extension is not "TXT"), you can simply open the file in text mode. Otherwise, you will not be interested in reading binary data in text mode.

_______________

  Nayer Naguib
0
lanac222Author Commented:
The file contents are numeric data generated at a POS. It should be readable text. But when I open with notepad it still shows binary code.
0
nayernaguibCommented:
This means that the file contents were somehow encoded (not necessarily for security reasons, maybe this is just a standard file format or something). Now what you did was *exactly* opening a file for reading in text mode! There will be nothing you can do better than that using C# unless you know first how to decode the file.

_______________

  Nayer Naguib
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.