C#读二进制文件.输出字符缓冲区太小的问题.路过的都来看看..散分!
报错为:
输出字符缓冲区太小,无法包含解码后的字符,编码“Unicode (UTF-8)”的操作回退“System.Text.DecoderReplacementFallback”。
参数名: chars
我每次读取100个字节...然后把读取的值赋给一个实体类的值..第一次读都没问题.大于第一次后...某些读取就开始报这个错误了..
下面代码是读取按钮事件里面的代码..贴了一部分..字段太多.
FileStream file=new FileStream(FileUpload1.PostedFile.FileName, FileMode.Open, FileAccess.Read);
FileInfo info = new FileInfo(FileUpload1.PostedFile.FileName);
BinaryReader reader=new BinaryReader(file);
Datarec datarec = new Datarec();
char[] chararray=new char[25];
string charvalue= " ";
string charminrf = " ";
string chardatarec = " ";
for (int j = 0; j < info.Length/100; j++)
{
datarec.baoformat = reader.ReadChar();
datarec.station = reader.ReadChar();
chararray = reader.ReadChars(6);
for (int i = 0; i < chararray.Length; i++)
{
charvalue += chararray[i].ToString();
}
datarec.stationname = charvalue;
chararray = null;
datarec.rectime = reader.ReadInt16();
datarec.recdate = reader.ReadUInt16();
datarec.wd2dd = reader.ReadInt16();
datarec.wd2df = reader.ReadInt16();
datarec.wd10dd = reader.ReadInt16();
datarec.wd10df = reader.ReadInt16();
高人指点..
------解决方案--------------------up
--