C# 使用FileStream.Read循環讀取固定長文件

使用FileStream.Read循環讀取固定長文件
FileStream fsFileRead = new FileStream(
  FileName,
  FileMode.Open,
  FileAccess.Read);

byteDataValue = new byte[LINE_SIZE];
charDataValue = new char[LINE_SIZE];

string strLine = string.Empty;
int intLength = 0;

while (fsFileRead.Read(byteDataValue, 0, byteDataValue.Length) == byteDataValue.Length)
{
  Encoding.Default.GetDecoder().GetChars(byteDataValue, 0, byteDataValue.Length, charDataValue, 0, true);
  strLine = new string(charDataValue);

  ...
  ...
  ...

  intLength += LINE_SIZE;
  fsFileRead.Seek(intLength, SeekOrigin.Begin);
}
 
其中,“fsFileRead.Seek(intLength, SeekOrigin.Begin);”一定要有。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章