I'm just now transitioning from C/C++ structured to C# and am working
with various file types in the learning process. My work in C involved
a lot of binary file I/O as well as a lot of text data file input and
conversion. Your question is one I have worked on recently too but do
not have fully resolved as yet ... but here's some comments >>
As others have pointed out ... the files are just streams of bytes and
it is how you are able to interpret them that is the key.
If the file is binary, you'd have to have the specific algorithm to
utilize it ... or be a very good code breaker. Using WinHex is a good
first look tool to use to see if you have any interest in that area.
It takes a little digging to get proficient with it ... but you can
certainly see every bit and various translations as you explore the
file.
If the file is text, the cultural and encoding attributes need to be
dealt with. If you are only working in English ... that simplifies
things greatly. My approach is to open the file in a RichTextBox and
view the first 2000 bytes. In a blink you'll know if it is readable or
gibberish.
As a learning project I am still polishing on an enhanced FilePicker
that began with Petzold's Directory TreeView and File ListView. I have
added a RichTextBox in a splitter panel below the tree and list
panels. I set it up as read only to assure no accidental editing
occurs. Select a file in the list and on the same form you get a fast
preview. Easy to recognize as text and also provides enough to usually
determine if it is the file I am targeting.
I'm still trying to get a working understanding of binding and
DataGridView to replace the list with a more feature packed class;
however, all that comes at price of speed and footprint. I'm not sure
if it is worth it ... but it sure provides a good focus to use for
learning. Also, I am working on a buffering algorithm to allow fast
viewing of huge data files without loading the entire file. Endless
enhancements are possible and such a project you might find fun.
If you decide to explore WinHex ... make a binary file with some known
values of doubles and various sized ints. Then when examining it you
will know what you are looking for and it becomes a lot easier. Also
open a short little NotePad txt file and give it a view. It's really
pretty interesting.
Best of Luck.
-- Tom
On Thu, 13 Dec 2007 18:17:17 +0200, "Alexander Vasilevsky"
<ma**@alvas.netwrote:
>How do I know whether the file is text or binary?
http://www.alvas.net - Audio tools for C# and VB.Net developers + Christmas
discount