Read file up to 1024 bytes of data in csharp
Stream stream = File.OpenRead(@"C:\data\file.xml"); int bytesToRead = 1024; int bytesRead = 0; byte [ ] buffer = new byte [bytesToRead]; // Fill up the buffer repeatedly until we reach the end of file do { bytesRead = stream.Read(buffer, 0, bytesToRead); Console.Write(Encoding.ASCII.GetChars(buffer,0, bytesRead)); } while (bytesToRead == bytesRead); stream.Close( );
Filed Under: C# Streams