There might be something obvious I'm missing here, but I can't seem to set the encoding on my FileStream read. Here's the code:
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
using (fs)
{
byte[] buffer = new byte[chunk];
fs.Seek(chunk, SeekOrigin.Begin);
int bytesRead = fs.Read(buffer, 0, chunk);
while (bytesRead > 0)
{
ProcessChunk(buffer, bytesRead, database, id);
bytesRead = fs.Read(buffer, 0, chunk);
}
}
fs.Close();
Where ProcessChunk saves the read values to objects which are then serialized to XML, but the characters read appear wrong. The encoding needs to be 1250. I haven't seen an option to add the encoding to the FileStream. What am I missing here?
StreamWriter
instead ofFileStream
ProcessChunk
whose code is missing. AFileStream
only returns bytesProcessChunk
. How does it convert bytes to text? You can avoid the problem if you use the1250
encoding, either in a StreamReader or withEncoding.GetString
. You can get it withEncoding.GetEncoding(1250)