原理:循环读取文件中的每一个字节,如果存在字节为0的情况,那么该文件不是文本文件 例子程序: using System; namespace Test1 ... { /**//**//**//// <summary> /// Summary description for Class1. /// </summary> class Class1 ...{ /**//**//**//// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) ...{ // // TODO: Add code to start application here // string path = @"C:Documents and Settingsspool shiDesktop im940_2.dat"; if (new Class1().isTextFile(path)) Console.WriteLine("True"); else Console.WriteLine("False"); } public bool isTextFile(string path) ...{ if (System.IO.File.Exists(path)) ...{ System.IO.FileStream file = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] byteData = new byte[1]; while(file.Read(byteData, 0, byteData.Length) > 0) ...{ if (byteData[0] == 0) return false; } return true; } return false; } }}