You're damn right it's not 100%. The first character in the ASCII character
set has a code of 0 (zero) and is named NUL.
Using NUL as a delimiter in a data file that otherwise contains 'text' is a
very valid practice that is widely used.
Unless a given file has a special feature, such as as preamble that provides
such information (some UTF encoded files contain such a preamble to indicate
the spefic UTF encoding used), there is no way of determining (from the
content) if a file should be treated as binary or text.
Passing data by way of a file is a form of a contract in which the provider
usually says 'I will produce files is such-and-such a way and here is the
documentation to enable you to interpret the content'.
Way too may people seem to think that they can grab any old data file and
that there will be a magic bullet so that they can read the file without
having to think about how they should be doing it.
One sure way way is to open the file in question is your favourtie editor
and eyeball the content. If it looks like readable text then it probably is.
If it doesn't look like readable text then reading it binary it probably the
way to go.
If in doubt ask the producer of the file!!!!!!!!!!!!
<ga********@myway.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
If you are dealing with just ASCII text and not Unicode.
You could start reading the file for binary access. Check in the using
block if any of the bytes are zero, if so return false, if not return
true.
This isn't 100% but it would be very unlikely for you to find a zero
byte in an 'ordinary' text file.
I'm sure there are better ways of doing this? But this is the only
logical way I can think of.
I cant find any predefined methods for determining this?
HTH Gary.
Ympostor wrote:
>Hello.
Is there a method in the .NET class libraries to know if a given file is
binary or just plain text (ASCII)?
Thanks in advance.
--