[C#] [CF] [VS 2005 B2] FileStream ?
FileStream { { value = } }
When i write that all the logged message shox the same thing Where ever i am...![]()
fileStream.Length == fileStream.Position
FileStream { { value = } }
When i write that all the logged message shox the same thing Where ever i am...![]()
fileStream.Length == fileStream.Position
Here is a sample file.
line1 line2 line3 line4 line5 line6 |
here is the reading code...
FileStream CSLogger.Debug("stream length = " + fileStream.Length); and now the log file...
StreamReader streamReader = new StreamReader(fileStream);
CSLogger.Debug("read {0} pos {1} ", streamReader.ReadLine(), fileStream.Position);
CSLogger.Debug("read {0} pos {1} ", streamReader.ReadLine(), fileStream.Position);
CSLogger.Debug("read {0} pos {1} ", streamReader.ReadLine(), fileStream.Position);
CSLogger.Debug("read {0} pos {1} ", streamReader.ReadLine(), fileStream.Position);
CSLogger.Debug("read {0} pos {1} ", streamReader.ReadLine(), fileStream.Position);
2005/07/21 - 16:42:43:000 #Debug Level# stream length = 45
2005/07/21 - 16:42:43:000 #Debug Level# read line1 pos 45
2005/07/21 - 16:42:43:000 #Debug Level# read line2 pos 45
2005/07/21 - 16:42:43:000 #Debug Level# read line3 pos 45
2005/07/21 - 16:42:43:000 #Debug Level# read line4 pos 45
2005/07/21 - 16:42:43:000 #Debug Level# read line5 pos 45
FileStream.Position is the same as FileStream.Length in this case because StreamReader maintains an internal buffer on top of FileStream. When you do a StreamReader.ReadLine(), the internal buffer is filled with the actual contents of the FileStream object, in this case the contents of the entire file. This explains why the FileStream position stays the same as you read through the file with StreamReader. To obtain positional information about the file, either count the size of the array returned by StreamReader.ReadLine(), or use FileStream.Read() directly.
Cheers,
Anthony [MSFT]