File.OpenRead
using System;
using System.Windows.Forms;
using System.IO;
class MainClass
{
public static void Main()
{
FileStream inStream = File.OpenRead("c:\\text.txt");
FileStream outStream = File.OpenWrite("c:\\text.txt" + ".bak");
BufferedStream bufInStream = new BufferedStream(inStream);
BufferedStream bufOutStream = new BufferedStream(outStream);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = bufInStream.Read(buf, 0, 1024)) > 0)
bufOutStream.Write(buf, 0, bytesRead);
bufOutStream.Flush();
bufOutStream.Close();
bufInStream.Close();
outStream.Close();
inStream.Close();
}
}
Related examples in the same category