创建流时无需创建物理文件 [英] Create a Stream without having a physical file to create from

查看:70
本文介绍了创建流时无需创建物理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个包含服务器上存在的文档的zip文件.我正在使用.Net Package类来执行此操作,并创建一个新的Package(它是zip文件),我必须具有物理文件或流的路径.我试图不创建将是zip文件的实际文件,而是仅创建将存在于内存或其他内容中的流.

I'm needing to create a zip file containing documents that exist on the server. I am using the .Net Package class to do so, and to create a new Package (which is the zip file) I have to have either a path to a physical file or a stream. I am trying to not create an actual file that would be the zip file, instead just create a stream that would exist in memory or something.

我的问题是如何在没有物理文件实例化的情况下如何实例化新的Stream(即FileStream,MemoryStream等).

My question is how do you instantiate a new Stream (i.e. FileStream, MemoryStream, etc) without having a physical file to instantiate from.

推荐答案

构造函数重载,都不需要文件.

MemoryStream has several constructor overloads, none of which require a file.

这篇关于创建流时无需创建物理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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