C#

/// <summary>/// Copies the contents of input to output. Better to close both stream after done./// </summary>publicstaticvoidCopyStream(Streaminput,Streamoutput){byte[]buffer=newbyte[input.Length];intlen;while((len=input.Read(buffer,0,buffer.Length))>0){output.Write(buffer,0,len);}input.Close();output.Close();}/// We can use it to Write file from assembly resource stream to disk, for example:StreamresourceStream=Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Namespace.SomeFolder.DbScript.sql");StreamoutputFile=File.OpenWrite(@"d:\sql.sql");CopyStream(resourceStream,outputFile);