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();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM