public static void Copy(Stream input, string targetFile, int length) { byte[] buffer = new byte[8192]; using (Stream output = File.OpenWrite(targetFile)) { int bytesRead = 1; while (length > 0 && bytesRead > 0) { bytesRead = input.Read(buffer, 0, Math.Min(length, buffer.Length)); output.Write(buffer, 0, bytesRead); length -= bytesRead; } } } public static void CopyFile(string sourceFile, string targetFile) { if (File.Exists(targetFile)) { File.Delete(targetFile); } Stream input = File.OpenRead(sourceFile); Copy(input, targetFile, (int)input.Length); System.GC.Collect(); }
2012/02/07
0 comments:
Post a Comment