static void Main(string[] args)
{
FileStream fs;
try
{
fs = new FileStream("D://a.jpg", FileMode.Open);
}
catch
{
Console.WriteLine("文件不存在");
return;
}
MemoryStream ms = new MemoryStream();
byte[] buffer = new byte[4096];
int count = 0;
while ( (count = fs.Read(buffer,0,buffer.Length)) > 0)
{
ms.Write(buffer, 0, count);
}
Console.WriteLine(fs.Length);
Console.WriteLine(ms.Length);
Console.Read();
} |