Idea: The multimedia file that you want to copy is read out and then written to the location you specified
C:\Users\Administrator\Desktop\01 class. avi
String Source = @ "C:\Users\Administrator\Desktop\01 class. avi";
String target = @ "C:\Users\Administrator\Desktop\ copy. avi";
CopyFile (Source,target);
Console.WriteLine ("Copy succeeded");
Console.readkey ();
}
public static void CopyFile (string soucrce, string target)
{
1, create a stream that is responsible for reading
using (FileStream fsread = new FileStream (Soucrce, FileMode.Open, FileAccess.Read))
{
Create a stream that is responsible for writing
using (FileStream fswrite=new FileStream (target,filemode.openorcreate,fileaccess.write))
{
Byte[] Buffer=new byte[1024*1024*5];
Because the file might be larger, we should read it through a loop when we read it.
while (true)
{
Returns the number of bytes actually read from this read
int r = fsread.read (buffer, 0, buffer. Length);
If you return a 0, it means that nothing is read.
if (r==0)
{
Break
}
Fswrite.write (BUFFER,0,R);
}
}
}
}
Using file streams for multimedia file replication