admin 管理员组

文章数量: 1184232

        public int GetFileType(string filePath)
        {
            int result = 0;
            if (File.Exists(filePath) == false)
            {
                return 0;
            }
            try
            {
                FileStream fs = new FileStream(filePath, FileMode.Open);
                int byteA = fs.ReadByte();                  //byte[0]
                int byteB = fs.ReadByte();                  //byte[1]
                fs.ReadByte();                              //byte[2]
                int byteC = fs.ReadByte();                  //byte[3]
                int byteD = fs.ReadByte();                  //byte[4]
                fs.Close();
                fs.Dispose();
                //ZIP:1
                if (byteA == 80 && byteB == 75)
                {
                    result = 1;
                }
                //LZH:2
                else if (byteC == 108 && byteD == 104)
                {
                    result = 2;
                }
                //TGZ:3
                else if (byteA == 31 && byteB == 139)
                {
                    result = 3;
                }
                //UNKNOWN:0
                else
                {
                    result = 0;
                }
            }
            catch
            {
                return 0;
            }
            return result;
        }

本文标签: 中如何检 编程 深入浅出