是文本文件吗?

问题描述:

你可以写一个程序来判断文件是否是文本文件

can u write a program to tell whether a file is a text file or not


你能不能写一个程序来判断文件是否是文本文件
can u write a program to tell whether a file is a text file or not





通常区分文本文件的唯一方法是txt后缀。但是您可以将该后缀添加到您喜欢的任何文件中。没有什么可以检查来证明文件绝对是文本文件。它只是磁盘上的数据字节。大多数文本文件都有一些常见的属性,并非所有文件都适用。所以答案是否定的。

Hi
The only thing that normally distinguishes a text file is the txt suffix. But you can give that suffix to any file you like. There is nothing to check for to prove that a file absolutely is a text file or not. It is just bytes of data on disk. There are some properties that are common to most text files and that is not true of all files. So the answer is no.


我想我会不同意你willakawill。


文本文件只包含可打印字符和新行。所以打开文件并检查每个字符以确保它符合我将提出的标准。
I think I would disagree with you willakawill.

A text file is one that only contains printable characters plus newlines. So openning the file and checking every character to make sure it fitted that criteria would be the test I would put forward.




我不确定windows,但是unix提供了一个名为file的实用程序。这可以用来知道文件的属性。使用系统函数我们可以从c程序执行这个命令。
Hi,
I am not sure about windows, but unix provides an utility called "file" which can be used to know the properties of a file. using "sytem" funciton we can execute this command from c program.