如何打开从内存流文件 [英] How to open a file from Memory Stream

查看:275
本文介绍了如何打开从内存流文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能直接从打开的文件的的MemoryStream 反对写入磁盘,做的Process.Start()?特别是PDF文件?如果不是这样,我想我需要写的的MemoryStream 到磁盘(这是一种恼人)。可能有人再点我一个关于如何写的MemoryStream 来磁盘资源?

Is it possible to open a file directly from a MemoryStream opposed to writing to disk and doing Process.Start() ? Specifically a pdf file? If not, I guess I need to write the MemoryStream to disk (which is kind of annoying). Could someone then point me to a resource about how to write a MemoryStream to Disk?

推荐答案

这取决于客户端:)上如果客户端会从标准接受输入你可以的的DTA的客户端。另一种可能性是写一个命名管道服务器或一个套接字服务器 - 不是小事,但它可能工作。

It depends on the client :) if the client will accept input from stdin you could push the dta to the client. Another possibility might be to write a named-pipes server or a socket-server - not trivial, but it may work.

不过,最简单的办法是只抓一个。临时文件和写入(事后删除)

However, the simplest option is to just grab a temp file and write to that (and delete afterwards).

var file = Path.GetTempFileName();
using(var fileStream = File.OpenWrite(file))
{
    var buffer = memStream.GetBuffer();
    fileStream.Write(buffer, 0, (int)memStream.Length);
}



记住要清理文件,当你完成。

Remember to clean up the file when you are done.

这篇关于如何打开从内存流文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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