Posted on 2011-05-08
Hi, I'm using VB.NET2010 (VS2010), WinForms. I have a TXT file which I'm reading into a FileStream and then using StreamReader to process the file.
I'm experiencing a unique issue with the FileStream.Length property, which is giving me a character count larger than the number of characters in the actual file.
My file contains 51314 characters. I've tested this by reading the number of characters per line in the file and summing them after each loop, while the file is being read. The sum = 51314
The FileStream.Length property returns a count of 53554 characters.
The difference = 2240 characters. (FS.length - SUM(number of characters per line))
However, what's interesting is that the line count = 1120 lines, which are read one line at a time.
Inspecting this further; 2240/1120 = 2. So, it seems that the FileStream.Length property is adding 2 characters per line...why? Is it taking into consideration the newline character and counting that as 2 per line?
Thanks for your help in helping me understand this...