在下面,我从蓝牙设备读取文件。有什么方法可以改善代码和速度吗?
using (FileStream fs = new FileStream(destination,
FileMode.OpenOrCreate,
FileAccess.ReadWrite))
{
byte[] firstByte = new byte[1] { (byte)readByte };
fs.Write(firstByte, 0, 1);
// Size is idenitifed. Read till that size.
for (int i = 1; i < fileSizeInBytes; i++)
{
readByte = 0;
byte[] fb = new byte[1];
if ((readByte = inStream.Read(fb, 0, 1)) > 0)
{
fs.Write(fb, 0, readByte);
}
}
}
答案 0 :(得分:0)
尝试使用它-它会创建一个更大的新字节数组,并复制您的元素中的元素。
Array.Resize(ref readByte, 1024);