using System.IO; using System.Net.Sockets; FileStream fileStream = new FileStream("input.txt", FileMode.Open); TcpClient client = new TcpClient("localhost", 8080); NetworkStream networkStream = client.GetStream(); await fileStream.CopyToAsync(networkStream); networkStream.Close(); client.Close();
using System.IO; MemoryStream memoryStream = new MemoryStream(); byte[] buffer = Encoding.ASCII.GetBytes("Hello World!"); memoryStream.Write(buffer, 0, buffer.Length); FileStream fileStream = new FileStream("output.txt", FileMode.Create); await memoryStream.CopyToAsync(fileStream); fileStream.Close();Both of these examples use the System.IO namespace for the CopyToAsync method.