2011-08-31 164 views

回答

24

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

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); 
     } 
    } 
}