如何将zip文件转换为字节数组 [英] how to covert zip file into Byte Array

查看:170
本文介绍了如何将zip文件转换为字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,如何在c#中将zip文件转换为字节数组

Dear Friends how to convert zip files in to byte arrays in c#

推荐答案

尝试以下操作:
Try this:
private byte [] StreamFile(string filename)
{
   FileStream fs = new FileStream(filename, FileMode.Open,FileAccess.Read);

   // Create a byte array of file stream length
   byte[] ImageData = new byte[fs.Length];

   //Read block of bytes from stream into the byte array
   fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));

   //Close the File Stream
   fs.Close();
   return ImageData; //return the byte data
}




并查看CP文章:
将数据集转换并压缩为字节数组 [ ^ ]

检查以供参考:
邮政编码压缩C#示例 [




and have a look on CP article:
Converting and Compressing a Dataset to Byte array[^]

Check this for reference:
Zip Compression C# Examples[^]


简短地使用以下内容:
using System.IO;

byte [] data=File.ReadAllBytes("C:\\file.zip");

祝您好运.

添加了前置标签.

Best of luck.

Added pre tags.




尝试以下代码
Hi,

try Following Code
private byte[] StreamFile(string filename)
    {
        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);

        // Create a byte array of file stream length
        byte[] byteData = new byte[fs.Length];

        //Read block of bytes from stream into the byte array
        fs.Read(byteData, 0, System.Convert.ToInt32(fs.Length));

        //Close the File Stream
        fs.Close();
        return byteData; //return the byte data
    }



希望本《规范》对您有所帮助
祝你好运
快乐编码:)



Hope this Code help U
Best Luck
Happy Coding:)


这篇关于如何将zip文件转换为字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆