C#写二进制文件,只写入byte[]数组的前两个数字,后面的都没写入,为什么?代码如下
FileStreamfs;fs=newFileStream("C:\\BloodPressure.bin",FileMode.OpenOrCreate,FileAcces...
FileStream fs;
fs = new FileStream("C:\\BloodPressure.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
byte[] buffer = { 22, 2, 0, 0, 0, 0, 0, 0, 0, 150, 0, 80, 0, 160, 0 };
bw.Write(buffer,0,buffer.Length);
fs.Close();
bw.Close(); 展开
fs = new FileStream("C:\\BloodPressure.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
byte[] buffer = { 22, 2, 0, 0, 0, 0, 0, 0, 0, 150, 0, 80, 0, 160, 0 };
bw.Write(buffer,0,buffer.Length);
fs.Close();
bw.Close(); 展开
展开全部
private void method()
{
byte[] buffer = { 22, 2, 0, 0, 0, 0, 0, 0, 0, 150, 0, 80, 0, 160, 0 };
using (FileStream fs = new FileStream(@"C:\BloodPressure.bin", FileMode.CreateNew, FileAccess.ReadWrite))
{
using (BinaryWriter writer = new BinaryWriter(fs))
{
writer.Write(buffer, 0, buffer.Length);
}
}
}
这样写经过了验证是ok的.
{
byte[] buffer = { 22, 2, 0, 0, 0, 0, 0, 0, 0, 150, 0, 80, 0, 160, 0 };
using (FileStream fs = new FileStream(@"C:\BloodPressure.bin", FileMode.CreateNew, FileAccess.ReadWrite))
{
using (BinaryWriter writer = new BinaryWriter(fs))
{
writer.Write(buffer, 0, buffer.Length);
}
}
}
这样写经过了验证是ok的.
展开全部
fs.Close();
bw.Close();
换成
bw.Close();
fs.Close();
bw.Close();
换成
bw.Close();
fs.Close();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这么写没问题啊。。
你试试在fs.close()之前fs.Flush();
你试试在fs.close()之前fs.Flush();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询