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
Post a Comment