Csharp/C#教程:如何从资源中复制文件?分享


如何从资源中复制文件?

我有一个嵌入式资源文件,例如: file.exe如何在目录中复制,例如: c: ? 点击按钮谢谢

您可以使用Assembly.GetManifestResourceStream来获取从中读取资源的流。 然后将其复制到FileStream 。 如果您使用的是.NET 4,则可以使用Stream.CopyTo轻松实现:

上述就是C#学习教程:如何从资源中复制文件?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 private void CopyResource(string resourceName, string file) { using (Stream resource = GetType().Assembly .GetManifestResourceStream(resourceName)) { if (resource == null) { throw new ArgumentException("No such resource", "resourceName"); } using (Stream output = File.OpenWrite(file)) { resource.CopyTo(output); } } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/950851.html

(0)
上一篇 2021年11月17日
下一篇 2021年11月17日

精彩推荐