文件 转换 二进制

将文件转换为二进制

复制代码
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就可以了

你可能感兴趣的:(二进制)