public Read ( byte array, int offset, int count ) : int | ||
array | byte | |
offset | int | |
count | int | |
return | int |
using (var stream = new FileStream("myfile.txt", FileMode.Open)) using (var bufferedStream = new BufferedStream(stream)) { byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = bufferedStream.Read(buffer, 0, buffer.Length)) > 0) { Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, bytesRead)); } }In this example, we create a FileStream for reading data from a file and wrap it in a BufferedStream. We then read data from the BufferedStream in chunks of 1024 bytes and convert it to a string using UTF8 encoding. Example 2: Writing data to a file using BufferedStream ``` using (var stream = new FileStream("myfile.txt", FileMode.Create)) using (var bufferedStream = new BufferedStream(stream)) { string message = "Hello world!"; byte[] buffer = Encoding.UTF8.GetBytes(message); bufferedStream.Write(buffer, 0, buffer.Length); } ``` In this example, we create a FileStream for writing data to a file and wrap it in a BufferedStream. We then write a string to the BufferedStream, which is converted to a byte array using UTF8 encoding. The System.IO.BufferedStream class is part of the System.IO namespace in the .NET Framework Class Library.