zoukankan      html  css  js  c++  java
  • c#将文件以二进制形式存入数据库

    二进制在mssql数据库中是VARBINARY(max)

    将文件转换为二进制

    public byte[] getContent(string path)
            {
                
                System.IO.FileStream fs = new System.IO.FileStream(@path, System.IO.FileMode.Open);
                fs.Position = 0;
                byte[] content = new byte[fs.Length];
                fs.Read(content, 0, (int)fs.Length);
                fs.Close();
                return content;
            }

    将二进制转换为文件

            public void save(byte[] content,string path)
            {
                System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
                System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
                bw.Write(content, 0, content.Length);
                bw.Close();
            }

    数据库存取的话 就是个普通的insert,select就可以了

  • 相关阅读:
    Kattis
    Kattis
    Kattis
    Kattis -Backspace
    Kattis
    Kattis
    Kattis
    Hihocoder1061-Beautiful String
    Hihocoder1350-Binary Watch
    Hihocoder1458-Parentheses Matching(stack,vector)
  • 原文地址:https://www.cnblogs.com/mengxingxinqing/p/3123872.html
Copyright © 2011-2022 走看看