我似乎无法找到一种更有效的方法将嵌入式资源"复制"到磁盘,而不是以下方法:
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
似乎没有更直接的方式来复制,除非我遗漏了一些东西......