using System.IO; // Create a new memory stream MemoryStream memStream = new MemoryStream(); // Add some bytes to the stream byte[] bytes = { 0x41, 0x42, 0x43, 0x44 }; memStream.Write(bytes, 0, bytes.Length); // Read the bytes from the stream byte[] readBytes = memStream.ToArray();
using System.IO; // Create a new file stream FileStream fileStream = new FileStream("example.txt", FileMode.Create); // Create a new stream writer StreamWriter streamWriter = new StreamWriter(fileStream); // Add a string to the stream string str = "Hello, world!"; streamWriter.WriteLine(str); // Close the stream writer and file stream streamWriter.Close(); fileStream.Close();In this example, we create a new `FileStream` object and use it to create a `StreamWriter`. We then add a string to the stream using the `WriteLine` method. Finally, we close the stream writer and file stream. Package library: `System.IO`