• 判断文件后缀


    通过文件头判断文件类型、后辍

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string path = @"E:b55b319ebc4b745d931e035cefc1e178a82156f";
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader r = new BinaryReader(fs))
                    {
                        string bx = "";
                        byte buffer;
                        try
                        {
                            buffer = r.ReadByte();
                            bx = buffer.ToString();
                            buffer = r.ReadByte();
                            bx += buffer.ToString();
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine(exc.Message);
                        }
                        Console.WriteLine(bx);
                        Console.ReadLine();
                    }
                }
            }
        }
    }

    常见文件类型对应编码

            JPG = 255216,
            GIF = 7173,
            BMP = 6677,
            PNG = 13780,
            COM = 7790,
            EXE = 7790,
            DLL = 7790,
            RAR = 8297,
            ZIP = 8075,
            XML = 6063,
            HTML = 6033,
            ASPX = 239187,
            CS = 117115,
            JS = 119105,
            TXT = 210187,
            SQL = 255254,
            BAT = 64101,
            BTSEED = 10056,
            RDP = 255254,
            PSD = 5666,
            PDF = 3780,
            CHM = 7384,
            LOG = 70105,
            REG = 8269,
            HLP = 6395,
            DOC = 208207,
            XLS = 208207,
            DOCX = 208207,
            XLSX = 208207

    参考资料:http://baike.baidu.com/link?url=ou1rjPoTKCnvIghdTdaL-QdSpgCaVm9qETOMoqBJxcj43N2OGgcyymH2-EfAj27ecuwQhasGBHXey9C-qC7bmK

  • 相关阅读:
    Redis 介绍1
    浅议javascript的内存泄露
    Redis 介绍2——常见基本类型
    常见的排序算法二——希尔排序
    Mono 学习之旅二
    Mono 学习之旅一
    常见的排序算法三——冒泡排序
    微软的面试题
    八大排序算法总结 1直接插入排序
    windows phone7 项目一俄罗斯方块源码 及说明
  • 原文地址:https://www.cnblogs.com/tqlin/p/5178303.html
Copyright © 2020-2023  润新知