如何从 FileStream 创建新文件?

发布于 2024-08-23 22:31:32 字数 232 浏览 13 评论 0原文

我有一个 javascript 文件作为程序集中的嵌入式资源,并且我正在尝试使用“System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("someName");”中的流创建一个新的 FileInfo 对象。我的困惑是如何使用流来创建 FileInfo。如果有人能在这方面帮助我,我将不胜感激。我确信这可能是一件简单的事情,但简单通常是我似乎总是怀念的。

I have a javascript file as an embedded resource in an assembly, and I'm trying to use the Stream from "System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("someName");" to create a new FileInfo object. My confusion is how to use a stream to create the FileInfo. If anyone can help me in this I would be greatly appreciative. I'm sure it's probably something easy, but easy is usually what I always seem to miss.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初雪 2024-08-30 22:31:32

你不能。因为您有一个 Stream,并且 FileStream 继承自 Stream,所以并不意味着所有 Stream 实例都是 FileStream 实例(并且通过扩展,具有作为 Stream 源的文件)。

话虽如此,Stream 从调用返回是没有意义的
GetManifestResourceStream 将有一个与其关联的 FileInfo,就像 NetworkStream 也不会有与其关联的 FileInfo 实例一样。

You can't. Because you have a Stream, and FileStream inherits from Stream, it doesn't mean that all Stream instances are FileStream instances (and by extension, have files that are the source of the Stream).

That being said, it doesn't make sense that the Stream returned from the call to
GetManifestResourceStream would have a FileInfo associated with it, just like a NetworkStream wouldn't have a FileInfo instance associated with it either.

删除→记忆 2024-08-30 22:31:32

您必须创建文件,然后读取资源流,然后写入文件流。

You have to create the file, then read the resource stream, and write the file stream.

匿名的好友 2024-08-30 22:31:32

如果您确实需要 FileInfo,那么您可能必须将数据从嵌入式资源复制到文件系统上的文件中。 这个问题有一些示例代码。

If you really need a FileInfo, then you'll probably have to copy the data from your embedded resource out to a file on the file system. This question has some sample code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文