Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

best way to determine the file is binary or text in c#?

What are the best way to determine the file is a binary or plan text ?? I have used below code which is can determine 80-90% of file content.by checking byte by byte . But I need 100% accuracy please post your answers

 public bool IsBinary(byte[] bytes)
    {
        for (int i = 0; i < bytes.Length; i++)
            if (bytes[i] > 127)
            {
                for (int j = 1; j < 512 && j < bytes.Length; j++)
                {
                    if (bytes[j] == 0x00 && bytes[j - 1] == 0x00)
                    {
                        return true;
                    }
                }
                break;
            }

        return false;
    }

Comments