如果我正在读取字节数,我会这样做:
using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
int size = (int) stream.Length;
BinaryReader br = new BinaryReader(stream);
byte[] test = new byte[size];
test = br.ReadBytes(size);
br.Close();
}
但是由于我想阅读 Uint16,所以我很震惊:
using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
int size = (int) stream.Length;
BinaryReader br = new BinaryReader(stream);
float[] test = new byte[size/2];
for (int i = 0; i < size/2; ++i)
{
test[i] = br.ReadUInt16();
}
br.Close();
}
有没有更快的方法一次读取整个文件,或者速度差异可以忽略不计?