使用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);
}
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);”一定要有。