c#源码:
public static void ExtractFile(String resource, String path)
{
Assembly assembly = Assembly.GetExecutingAssembly();
BufferedStream input = new BufferedStream(assembly.GetManifestResourceStream(resource));
FileStream output = new FileStream(path, FileMode.Create);
byte[] data = new byte[1024];
int lengthEachRead;
while ((lengthEachRead = input.Read(data, 0, data.Length)) > 0)
{
output.Write(data, 0, lengthEachRead);
}
output.Flush();
output.Close();
}
public static void ExtractText(string str, String path)
{
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(str.Trim());
sw.Flush();
sw.Dispose();
sw.Close();
fs.Close();
}
public static void ExtractNormalFileInResx(byte[] resource, String path)
{
FileStream file = new FileStream(path, FileMode.Create);
file.Write(resource, 0, resource.Length);
file.Flush();
file.Close();
}
public static void ExtractAudioFileInResx(Stream fileInResx, String path)
{
Stream input = fileInResx;
FileStream output = new FileStream(path, FileMode.Create);
byte[] data = new byte[1024];
int lengthEachRead;
while ((lengthEachRead = input.Read(data, 0, data.Length)) > 0)
{
output.Write(data, 0, lengthEachRead);
}
output.Flush();
output.Close();
}
public static void ExtractImageFileInResx(Bitmap image, String path)
{
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, image.RawFormat);
byte[] data = memoryStream.ToArray();
FileStream file = new FileStream(path, FileMode.Create);
file.Write(data, 0, data.Length);
file.Flush();
file.Close();
}