根据二进制流判断文件类型

 

            string fileType = string.Empty;
            string path = @"C:\Users\xxxx\Desktop\woman.jpg";
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                for (int i = 0; i < 2; i++)
                {
                    fileType += fs.ReadByte().ToString();
                }
            }
            Console.WriteLine((FileType) Convert.ToInt32(fileType));



    public enum FileType
    {
        doc, xls, ppt, wps = 208207,
        docx, pptx, xlsx, zip = 8075,
        txt = 5150,
        gif = 7173,
        jpg = 255216,
        png = 13780,
        bmp = 6677,
    }

 

posted @ 2018-03-08 16:12  热敷哥  阅读(1220)  评论(0编辑  收藏  举报