using System; using System.IO; class Program { static void Main(string[] args) { FileStream fileStream = new FileStream("test.txt", FileMode.Open); while (fileStream.Position < fileStream.Length) { int byteRead = fileStream.ReadByte(); Console.Write((char)byteRead); } fileStream.Close(); } }
using System; using System.Net; using System.Net.Sockets; class Program { static void Main(string[] args) { TcpClient client = new TcpClient("localhost", 1234); NetworkStream networkStream = client.GetStream(); while (true) { int byteRead = networkStream.ReadByte(); Console.Write((char)byteRead); } client.Close(); } }In this example, we are reading data from a network stream using the ReadByte() method. We first create a TcpClient object that connects to a server running on localhost at port 1234. We then create a NetworkStream object that allows us to read data from the server. We use a while loop to read the data byte by byte using the ReadByte() method. We use the Console.Write() method to print each byte to the console. The package library used in these examples is "System.IO" which provides classes for reading and writing to files and streams.