Link to home
Start Free TrialLog in
Avatar of lanac222
lanac222

asked on

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
Avatar of nayernaguib
nayernaguib
Flag of Egypt image

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
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
Avatar of lanac222
lanac222

ASKER

but i'd like to convert the binary data to man readable text.
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
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.
ASKER CERTIFIED SOLUTION
Avatar of nayernaguib
nayernaguib
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial