可能有一些明显的我在这里失踪,但我似乎无法设置我的FileStream读取编码。代码如下:C#FileStream读取设置编码
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();
其中ProcessChunk将读取值保存到对象,然后将对象序列化为XML,但读取的字符显示为错误。编码需要是1250.我还没有看到将编码添加到FileStream的选项。我在这里错过了什么?
尝试使用StreamWriter而不是FileStream – tym32167
由于您正在读取* bytes *,因此没有编码。如果这些字节构成文本,则将这些字节转换为需要编码器的文本。代码或问题中没有任何文本处理的痕迹(除了“我在哪里指定编码器”),所以问题是:您是否需要编码器? –