C#通过文件头判断文件的类型(不是后缀名)

            FileStream fs=new FileStream(@"D:6",FileMode.Open,FileAccess.Read);
            BinaryReader reader= new BinaryReader(fs);
            string fileclass="";
            try{
                for(int i=0;i<2;i++)
                {
                    fileclass +=reader.ReadByte().ToString();
                }
            }catch(Exception ex)
            {
            MessageBox.Show(ex.Message);
            }

            if (fileclass == "8075")
            {
                MessageBox.Show("xlsx,zip,pptx,mmap,zip");
            }
            if (fileclass == "208207")
            {
                MessageBox.Show("xls.doc.ppt");
            }
            if (fileclass == "4944")
            {
                MessageBox.Show("csv");
            }
            fs.Close();
原文地址:https://www.cnblogs.com/hesijian/p/6476837.html