获取文件名的字节数组或流数组、文件名、字节

由网友(念念如酥)分享简介:是字节数组或流可能获取文件名?我不想保存文件。我只是想找回这个名字。Is possible get filename from byte array or stream?I do not want to save the file. I just want to retrieve the name.推荐答案如...

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

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.

阅读全文

相关推荐

最新文章