C#memorystream或任何流.从流中打开文件 [英] C# memorystream or any streams. open a file out of the stream

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

问题描述


我想知道是否可以在不将文件写入光盘的情况下读取或打开文件.这是我到目前为止所做的.

hey
I want to know if can read or open a file a any steam without writing a file to the disc. This is what i have done so far.

byte[] MyData = new byte[0]; //*this is my byte array. i wll get my bytes from my database,name,ect*// 
  MemoryStream stream = new MemoryStream(MyData); //now i have mydata in stream


从这里开始,我不知道继续.我只需要知道如何从流中打开文件.
请,我真的会非常感谢您的帮助.


我还尝试了


from here i don''t know to go on.All i need to know is how to open the file form the stream.
please i will really thank you for the help.


i also tried

FileStream fs2= null;
         FileStream fs = new FileStream(@"C:\sd.txt",FileMode.Open);
         byte[] data = new byte[fs.Length];
         fs.Read(data,0,(int)fs.Length);

         fs2.Read(data,0,(int)fs.Length);
         fs.Close();

         System.Diagnostics.Process.Start(fs2.Name);

推荐答案

您不能.它在流中,除了将其写在某个地方或存储以供使用之外,您无法对其进行任何操作.当它以纯二进制格式出现时,Windows无法打开不在硬盘驱动器上的程序.您只是在随机编写代码,试图做一些不可能的事情.
You can''t. It''s in a stream, you can''t do anything with it, apart from write it somewhere, or store it for your use. Windows can''t open a program that is not on the hard drive, when it''s in that pure binary form. You''re just writing code at random, trying to do something impossible.


您不能从流中创建新进程.它只能从磁盘上的文件启动.
You can not create a new process from a stream. It can only be launched from a file on disk.


您要做什么?

FileStream只不过是在文件周围公开流.另外,如果您有文件流,可以将其用于
1.字节级操作,例如加密解密.
2.使用标准或自定义压缩器(zip,rar)对其进行压缩.
3.如果您知道文件格式,则可以使用Filestream读取其标题(有关文件的固定长度信息,如何在文件上打包数据等).大多数文件(如JPEG,BMP等)都有标题.
What are you trying to do ?

FileStream is nothing but exposing a stream around the file. Also if you have a filestream you use it for
1. Byte level operations like encryption decryption.
2. Compress it using standard or custom deflator(zip, rar).
3. If you know the file format, then you can use Filestream to read its header(its fixed length information about the file, how data is packed on it etc). Headers are present for most of the files like JPEG, BMP etc.


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

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