本文整理汇总了C#中System.IO.BufferedStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.Write方法的具体用法?C# BufferedStream.Write怎么用?C# BufferedStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.Write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: for
// Send the data using the BufferedStream.
Console.WriteLine("Sending data using BufferedStream.");
startTime = DateTime.Now;
for(int i = 0; i < numberOfLoops; i++)
{
bufStream.Write(dataToSend, 0, dataToSend.Length);
}
bufStream.Flush();
bufferedTime = (DateTime.Now - startTime).TotalSeconds;
Console.WriteLine("{0} bytes sent in {1} seconds.\n",
numberOfLoops * dataToSend.Length,
bufferedTime.ToString("F1"));
示例2: Main
//引入命名空间
using System;
using System.Windows.Forms;
using System.IO;
public class MainClass
{
public static void Main()
{
OpenFileDialog dlgOpen = new OpenFileDialog();
dlgOpen.Title="Select file to back up";
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
FileStream inStream = File.OpenRead(dlgOpen.FileName);
FileStream outStream = File.OpenWrite(dlgOpen.FileName + ".bak");
BufferedStream bufInStream = new BufferedStream(inStream);
BufferedStream bufOutStream = new BufferedStream(outStream);
byte[] buf = new byte[4096];
int bytesRead;
while ((bytesRead = bufInStream.Read(buf, 0, 4096)) > 0)
bufOutStream.Write(buf, 0, bytesRead);
bufOutStream.Flush();
bufOutStream.Close();
bufInStream.Close();
outStream.Close();
inStream.Close();
}
}
}