FileStreamオペレーションファイルのコピー
3753 ワード
static void Main(string[] args)
{
string source = @"D:\c\ .avi";
string target = @"C:\Users\Administrator\Desktop\ 2.avi";
CopyFile(source, target);
Console.WriteLine(" ");
Console.ReadKey();
}
public static void CopyFile(string source, string target)
{
// using
using (FileStream fss = new FileStream(source, FileMode.Open, FileAccess.Read))
{
//
using (FileStream fst = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
{
byte[] buf = new byte[1024 * 1024 * 5];
// ,
while (true)
{
int intBy = fss.Read(buf, 0, buf.Length);
// 0
if (intBy == 0)
{
break;
}
//
fst.Write(buf, 0, intBy);
}
}
}
}
C# filestream.Readはwhileサイクルで何の役に立ちますか?FileStream fs = File.OpenRead("C:\\test.txt"); byte[] arr = new byte[100]; while (filestream.Read(arr, 0, arr.Length)>0) { Console.WriteLine(data.GetString(arr));}回答:ファイルを100バイトずつ読み返す