获取文件名的字节数组或流 [英] Get file name from byte array or Stream

查看:258
本文介绍了获取文件名的字节数组或流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是字节数组或流可能获取文件名? 我不想保存文件。我只是想找回这个名字。

Is possible get filename from byte array or stream? I do not want to save the file. I just want to retrieve the name.

推荐答案

如果在实际上是一个的FileStream ,那么这个的可以的可强制转换为的FileStream 和访问 .Name点属性:

If the Stream is actually a FileStream, then this may be available by casting to FileStream and accessing the .Name property:

Stream stream = ...
FileStream fs = stream as FileStream;
if(fs != null) Console.WriteLine(fs.Name);

不过,在一般情况下:不,这是不可用的。 A 字节[] 确实的文件的文件名的概念,也没有大多数其他类型的数据流。同样,的FileStream 基本流被包裹其他流(COM pression,加密,缓冲等)将不会公开这样的信息,尽管底层的流(几层向下)是一个文件。

However, in the general case: no, this is not available. A byte[] certainly has no concept of a filename, nor do most other types of streams. Likewise, a FileStream base-stream that is being wrapped by other streams (compression, encryption, buffering, etc) will not expose such information, despite the underlying stream (several layers down) being a file.

我会分开处理的文件名。

I would handle the filename separately.

这篇关于获取文件名的字节数组或流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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