FileStream Read 怎麼清空緩存呀
USB2.0閃盤,讀一個64MB的文件,第一次讀大概是4s左右,第一次以後,就只要0.1s了,初步懷疑是沒有清空緩存,但不知道在哪裡清空,請高手指點...謝謝!
DateTime StartTime,EndTime;
long FileSize;
double TestTime;
StartTime = DateTime.Now;
string strPath = string.Format(@"{0}{1}", Volume, FullFileName);
if (!File.Exists(strPath))
throw new Exception(string.Format("{0} 文件不存在,請先進行寫入測試!", strPath));
FileInfo f = new FileInfo(strPath);
FileSize = f.Length;
using (FileStream fs = new FileStream(strPath, FileMode.Open, FileAccess.Read, FileShare.None))
{
int length = (int)FileSize;
byte[] readBuf = new byte[FileSize];
int count;
int sum = 0;
while ((count = fs.Read(readBuf, sum, length - sum)) > 0)
sum += count;
EndTime = DateTime.Now;
fs.Close();
readBuf = null;
}
GC.Collect();
TestTime = (EndTime - StartTime).TotalMilliseconds;
usb
异常
补充:.NET技术 , C#