文件复制
FileStream fr = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read); FileInfo fi = new FileInfo(openFileDialog1.FileName); FileStream fw = new FileStream("f:\\"+fi.Name , FileMode.Create, FileAccess.Write); if (fr.CanRead) { long length = fr.Length; int size = 1024 * 1024; int count = (int)(length / size); int last = (int)(length % size); while (count > 0) { byte[] buffer = new byte[size]; fr.Read(buffer, 0, buffer.Length); fw.Write(buffer, 0, buffer.Length); count--; } if (last > 0) { byte[] buffer = new byte[last]; fr.Read(buffer, 0, buffer.Length); fw.Write(buffer, 0, buffer.Length); } fr.Close(); fw.Flush(); fw.Close(); MessageBox.Show("Done!"); }