二进制或文本文件 [英] Binary or text file

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

问题描述

嗨伙计,


我是Googlegroups的新手。我在其他论坛上问了我的问题,因为

现在。


我有一个重要的问题:我必须检查文件是否是

二进制(.bmp,.avi,.jpg)或文本(.txt,.cpp,.h,.php,.html)。如何

查看文件,找出文件是二进制还是文本?


感谢您的帮助。

Hi folks,

I am new to Googlegroups. I asked my questions at other forums, since
now.

I have an important question: I have to check files if they are
binary(.bmp, .avi, .jpg) or text(.txt, .cpp, .h, .php, .html). How to
check a file an find out if the file is binary or text?

Thanks for your help.

推荐答案

< li ** @ ubootsuxx.dewrote:
<li**@ubootsuxx.dewrote:

我是Googlegroups的新手。我在其他论坛上问了我的问题,因为

现在。


我有一个重要的问题:我必须检查文件是否是

二进制(.bmp,.avi,.jpg)或文本(.txt,.cpp,.h,.php,.html)。如何检查文件,如果文件是二进制文件还是文本,请查看文件?
I am new to Googlegroups. I asked my questions at other forums, since
now.

I have an important question: I have to check files if they are
binary(.bmp, .avi, .jpg) or text(.txt, .cpp, .h, .php, .html). How to
check a file an find out if the file is binary or text?



你不能。你只能很有可能确定文件是什么。

假设ASCII代码中只有极少数控制字符出现在

文本文件中。这就像找到一只白色的乌鸦,如果你只看了一只更多的乌鸦,它可能是一只白色的乌鸦。但是如果你有文件的文件

扩展器(如上所述),你可以查看Wotsit并得到答案。

http://www.wotsit.org/


你可以' T。您只能很有可能确定文件是什么。
You can''t. You can only determine with high probability what the file is.

假设ASCII代码中只有极少数控制字符出现在

文本文件中。
Assuming ASCII code only a very few of the control characters ever appear in
a text file.



这就是完成它的方式。如果你使用unix命令

`file''它就像这样。它通常需要

文件的前512个字节,从中可以确定

文件的类型。二进制文件往往有很多填充,字节为零,

out,而ascii文件的每个字节都有一个值30.

Thats pretty much the way to do it. If you take the unix command
`file'' it does it pretty much like this. It''ll generally take the
first 512 bytes of the file and from that it can determine the type of
file. Binary files tend to have a lot of padding with bytes zeroed
out, while ascii files will have every byte having a value 30.


On 5月10日下午3:16,Keith Halligan< keith.halli ... @ gmail.comwrote:
On May 10, 3:16 pm, Keith Halligan <keith.halli...@gmail.comwrote:

你可以' T。你只能很有可能确定文件是什么。

假设ASCII代码中只有极少数控制字符出现在

文本文件中。
You can''t. You can only determine with high probability what the file is.
Assuming ASCII code only a very few of the control characters ever appear in
a text file.



这就是完成它的方式。如果你使用unix命令

`file''它就像这样。它通常需要

文件的前512个字节,从中可以确定

文件的类型。二进制文件往往有很多填充,字节为零,

out,而ascii文件的每个字节都有一个值30.


Thats pretty much the way to do it. If you take the unix command
`file'' it does it pretty much like this. It''ll generally take the
first 512 bytes of the file and from that it can determine the type of
file. Binary files tend to have a lot of padding with bytes zeroed
out, while ascii files will have every byte having a value 30.



在unix中有一个''file''命令实用程序来完成这项工作

从中借用源代码:)

there is a ''file'' command utility in unix that does the job
borrow source code from it :)


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

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