>string sFileName = "C:\\NMCC\\MWD\\data20041203134748.mwd"; > >// Read the file using the stream reader to get the length of the file >System.IO.StreamReader oReader = System.IO.File.OpenText(sFileName); >string lcString = oReader.ReadToEnd(); >oReader.Close(); > >// Use the length to the string to determine size of byte[] >System.Byte[] myByte = new System.Byte[lcString.Length]; >System.IO.FileStream fs = new System.IO.FileStream(sFileName,System.IO.FileMode.Open, System.IO.FileAccess.Read); >System.IO.BinaryReader r = new System.IO.BinaryReader(fs); > >// ReadByte() in a for loop >for (int i = 0 ; i < lcString.Length; i++) >{ > myByte[i] = r.ReadByte(); >} >>
using System; using System.IO; class test { static void Main() { const int buflen=4096; // read in 4K blocks byte[] myBytes = new byte[buflen]; // buffer to read into int bytesRead; // will hold actual number of bytes read string sFileName = "C:\\NMCC\\MWD\\data20041203134748.mwd"; FileStream fs = File.OpenRead(sFileName); // Open file for reading while( (bytesRead = fs.Read( myBytes,0,buflen )) > 0 ) // while there are bytes read { for(int i=0;i < bytesRead;i++) {Console.Write( "[{0,3}]",myBytes[i].ToString() );} } } }bytesRead is the number of bytes read from stream. If 0, eof. It would be less than 'buflen' if fewer bytes left on stream.