When you say "on disk which says that it has 200,000 bytes", do you mean in Windows Explorer? That's rarely the exact file size because it reports file space allocated (block size).
>I have a file on disk which says that it has 200,000 bytes. This is from a right click on the file with Properties.
>
>My code is as follow:
>
>
> ' If the stream is not set yet
> If oStreamWriter Is Nothing Then
>
> ' If we cannot get the encoding
> loFileFunction.cFile = cFile
> If Not loFileFunction.GetEncoding() Then
>
> End If
>
> oStreamWriter = New StreamWriter(oFileStream, loFileFunction.cEncoding)
> End If
>
> loFile = New IO.StreamReader(cFile)
> oStreamWriter.Write(loFile.ReadToEnd())
> loFile.Close()
> nLength = oStreamWriter.BaseStream.Length
>
>
>Basically, I call loFileFunction.GetEncoding() to obtain the encoding of the file. It is ANSI. So, oStreamWriter can create the stream with the proper encoding. I verified that. The file is in fact created with ANSI encoding.
>
>Then, I use StreamReader() and make uses of its object ReadToEnd(). Just to be sure of the length I have at this point in the oStreamWriter, I store that into nLength. The value is 188416, which is very far from 200000. Where are the missing 11584 bytes?
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer