是否可以从字节数组中获取文件名? [英] Is it possible to get file name from byte array?

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

问题描述

https://www.codeproject.com/Questions/1187473/How -to-save-bytearray-to-PDF [ ^ ]



我正在开展项目,我需要将字节数组存储为PDF格式。



经过一番研究,我能够得到字节数组的文件类型。



是否可以从字节数组中获取文件名?



我有什么试过:



我试过这个链接的方法。

http://stackoverflow.com/questions/8741968/get-file-name-from-byte-array-or-stream [ ^ ]



抛出异常对象引用未设置为对象的实例。

https://www.codeproject.com/Questions/1187473/How-to-save-bytearray-to-PDF[^]

I am working on project in which i need to store byte array as PDF.

After some research, I am able to get file type of the byte array.

Is it possible to get file name from the byte array?

What I have tried:

I have tried methods from this link.
http://stackoverflow.com/questions/8741968/get-file-name-from-byte-array-or-stream[^]

It is throwing exception "Object reference not set to an instance of an object."

推荐答案

如果您尝试过其他网站的方法,最明智的做法是询问编写代码的人的问题,而不是完全不同的网站。

第二个最明智的做法是显示你尝试过的代码 - 正如你所尝试的那样 - 通过copy'n'pasting到你在不同网站上的问题。没有它,每个人都在猜测你究竟做了什么...

第三个最明智的事情(但我先做过的事情)就是使用调试器来看看到底是什么当我运行代码时继续。



但是......如果你有一个字节数组,那就是全部,它没有文件名 - 那些只是在操作系统文件系统中可用于实际文件,并且字节数组没有与之关联的任何文件,即使它是从文件读取或已写入文件。考虑一下:当你更改文件名时,它根本不会对文件内容进行任何更改 - 而字节数组只是文件内容,而没有任何其他包装材料,你可以通过文件流获得。所以在猜测中,您正在尝试将一个字节数组转换为流,并假设这将为您提供一个文件名。它不会。
If you have tried methods from a different site, the most sensible thing to do would be to ask a question of the person who wrote the code, not a different site completely.
The second most sensible thing would be to show the code you tried - as you tried it - by copy'n'pasting it into your question on the different site. Without that, everybody is just guessing what exactly you did...
The third most sensible thing (but the thing I'd have done first) would be to use the debugger to look at exactly what is going on when I ran the code.

But...if you have a byte array and that is all, it doesn't have a filename - those are only available within the operating system file system for actual files, and a byte array does not have any file associated with it, even if it was read from or has been written to a file. Think about it: when you change a file name it makes no change at all to the file content - and an array of bytes is just the file content without any other "wrapping" material that you might get with a filestream. So at a guess, you are trying to cast a byte array to a stream, and assuming that that will give you a file name. It won't.


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

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