• 判断文件后缀


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

    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

  • 相关阅读:
    CodeVs 1295 N皇后问题
    POJ 3349 Snowflake Snow Snowflakes
    链表API
    Hash API
    CodeVS 1220 数字三角形
    CodeVS 1045 回文数
    CodeVS 1058 合唱队形(DP--最长子序列问题)
    CodeVS 1018 单词接龙(DFS)
    关于图覆盖问题习题BY石家名
    软件测试作业(二)
  • 原文地址:https://www.cnblogs.com/tqlin/p/5178303.html
Copyright © 2020-2023  润新知