代码:
public void FileStreamWriteFile(string filePath, string str)
{
byte[] byData;
char[] charData;
try
{
FileStream fs = new FileStream(filePath, FileMode.Create);
charData = str.ToCharArray();
byData = new byte[charData.Length];
Encoding enc = Encoding.GetEncoding("GB2312");
enc.GetBytes(charData, 0, charData.Length,byData, 0);
//enc.GetBytes(charData, 0, charData.Length, byData, 0, true);
fs.Seek(0, SeekOrigin.Begin);
fs.Write(byData, 0, byData.Length);
fs.Close();
}
catch (Exception ex)
{
throw ex;
}
}
出现如题错误:输出字节缓冲区太小,无法包含编码后的数据,编码“简体中文(GB2312)”的操作回退“System.Text.InternalEncoderBestFitFallback”。
参数名: bytes
public void FileStreamWriteFile(string filePath, string str)
{
byte[] byData;
char[] charData;
try
{
FileStream fs = new FileStream(filePath, FileMode.Create);
charData = str.ToCharArray();
byData = new byte[charData.Length];
Encoding enc = Encoding.GetEncoding("GB2312");
enc.GetBytes(charData, 0, charData.Length,byData, 0);
//enc.GetBytes(charData, 0, charData.Length, byData, 0, true);
fs.Seek(0, SeekOrigin.Begin);
fs.Write(byData, 0, byData.Length);
fs.Close();
}
catch (Exception ex)
{
throw ex;
}
}
出现如题错误:输出字节缓冲区太小,无法包含编码后的数据,编码“简体中文(GB2312)”的操作回退“System.Text.InternalEncoderBestFitFallback”。
参数名: bytes
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货