Re: System.IO.File.IsBinary() ?



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!!!!!!!!!!!!


<garyusenet@xxxxxxxxx> wrote in message
news:1164820371.025225.287400@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.

--



.



Relevant Pages

  • Re: How do I convert 16 bit Binary to ASCII text
    ... tbob wrote: ... I noticed that the second substring's first character is not a zero as stated in your definition. ... You can do that by ANDing it with an appropriate integer. ...
    (comp.lang.labview)
  • Re: main() does not return when getchar() reaches EOF
    ... In article gazelle@xxxxxxxxxxxxxxxxxxxxx (Kenny McCormack) writes: ... I'm not sure what you mean by "submit zero bytes", ... A double ^D does the same when not the first character. ... winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131 ...
    (comp.lang.c)
  • Re: main() does not return when getchar() reaches EOF
    ... Kenny McCormack wrote: ... I'm not sure what you mean by "submit zero bytes", ... A double ^D does the same when not the first character. ... As Chris' post excellently explained, ...
    (comp.lang.c)
  • Re: leading zeros
    ... Don't use zeroes as the first character in your password? ... kidding. ... Enter a ' before the number or first select the column and format ... > When I move to a new cell it automatically drops the initial zero and is ...
    (microsoft.public.excel.misc)
  • Re: Read problem
    ... Use a / in a data file to terminate a record. ... Some compilers will set them to zero, but it is safer to set ...
    (comp.lang.fortran)

Loading