如何确定文件是否在C#二进制或文本? [英] How can I determine if a file is binary or text in c#?

查看:282
本文介绍了如何确定文件是否在C#二进制或文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要80%,以确定是否是二进制文件或文本,有没有办法做到这一点,甚至快速和肮脏的/在C#丑?

I need to determine in 80% if a file is binary or text, is there any way to do it even quick and dirty/ugly in c#?

推荐答案

我可能会寻找一个丰盈这将一般在一个二进制文件present但很少在一个文本文件中控制字符。二进制文件倾向于使用0,以至于只是测试了很多0字节很可能足以赶上大多数文件。如果你关心本地化你需要测试多字节模式也是如此。

I would probably look for an abundance of control characters which would typically be present in a binary file but rarely in an text file. Binary files tend to use 0 enough that just testing for many 0 bytes would probably be sufficient to catch most files. If you care about localization you'd need to test multi-byte patterns as well.

就好像说,你可以永远倒霉,并得到一个二进制文件看起来像文本,反之亦然。

As stated though, you can always be unlucky and get a binary file that looks like text or vice versa.

这篇关于如何确定文件是否在C#二进制或文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆