将资源数组从资源保存到文件 [英] Save Array of Byte from Resources to a File

查看:134
本文介绍了将资源数组从资源保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在创建一个代码,可以将Source of Byte从Resource保存到文件中。

所以我去解决方案资源管理器>属性>资源标签>并设置文件(ctrl + 5)。



这是我的代码:

  byte  [] picArray = System.IO.File.ReadAllBytes(Properties.Resources.File); 

System.IO.File.WriteAllBytes( @ Path,picArray );







此代码必须将(Properties.Resources.File)分配给picArray,但是它运行时出现错误路径中存在非法字符。在第一行,



我可以做些什么来解决这个问题?

提前感谢。

解决方案

问题是您正在尝试使用资源中的数据从磁盘读取文件作为文件的路径。



它没有分配(Properties.Resources.File)到picArray它试图使用该信息与文件路径相反。也许你想要这个:

  byte  [] picArray =(字节 [])Properties.Resources.File; 
System.IO.File.WriteAllBytes( @ Path,picArray);


Hi ,
I am creating a code that can save Array of Byte from Resource to a file .
So I go to Solution explorer > Properties > Resource tab > and set Files (ctrl + 5 ) .

This is my code :

byte[] picArray = System.IO.File.ReadAllBytes(Properties.Resources.File);

System.IO.File.WriteAllBytes(@"Path", picArray);




this code must Assign( Properties.Resources.File) to picArray , But it run with error "Illegal characters in path." in first line ,

what i can do to solve this problem ?
thanks in advance .

解决方案

The problem is that you are trying to read the file from the disk, using the data in your resources as the path to the file.

It doesn't "Assign( Properties.Resources.File) to picArray" it tries to use that info as as file path instead. Probably, you want this instead:

byte[] picArray = (byte[])Properties.Resources.File;
System.IO.File.WriteAllBytes(@"Path", picArray);


这篇关于将资源数组从资源保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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