我似乎找不到比以下方法更有效的方法来将嵌入式资源“复制”到磁盘:
using (BinaryReader reader = new BinaryReader(
assembly.GetManifestResourceStream(@"Namespace.Resources.File.ext")))
{
using (BinaryWriter writer
= new BinaryWriter(new FileStream(path, FileMode.Create)))
{
long bytesLeft = reader.BaseStream.Length;
while (bytesLeft > 0)
{
// 65535L is < Int32.MaxValue, so no need to test for overflow
byte[] chunk = reader.ReadBytes((int)Math.Min(bytesLeft, 65536L));
writer.Write(chunk);
bytesLeft -= chunk.Length;
}
}
}
似乎没有更直接的方法来进行复制,除非我丢失了某些东西...
慕田峪9158850
拉丁的传说