如何识别文件是垃圾文件或可转换文件

人气:136 发布:2022-09-22 标签: c# vb.net vb VB.NET

问题描述

在文本框中输入任何类型的文件并且检查文件是垃圾文件或可转换文件

Input any type of Files in Text Box And Check It file is junk file or Convertible File

推荐答案

一般来说,你不能。 如果幸运的话,可转换文件的范围仅包括以文件类型标记开头的文件,或者具有标识文件类型的唯一扩展名(最好是两者),那么您可以查看扩展名,它可能是什么,然后检查文件数据以识别字节。 但大多数文件格式没有识别数据,而那些经常重复使用的文件格式不同格式的字节值,因为没有单一的寄存器文件类型 - 每个程序员都可以自由创建自己的。 所以你最好的解决方案是看看扩展,看看它是否是你知道的 - 然后尝试适当的转换器,看它是否有效。如果确实如此,那么很好 - 如果没有,请报告问题。 In general, you can't. If you are lucky, and the range of "Convertible Files" include only files that start with a file type marker, or have unique extensions which identify the file type (preferably both) then you can look at the extension, decide what it could be, and then check the file data for identifying bytes. But most file formats don't have identifying data, and those that do often reuse the same byte values for different formats because there is no single "register" of file types - every programmer is free to invent his own. So your best solution is to look at the extension, and see if it is one you know - then try the appropriate converter and see if it works. If it does, great - if it doesn't, report a problem.

744