检测文件流RFileReadStream读到文件结尾

检测文件流结尾
调用MStreamBuf::SizeL()来获取文件的大小,然后调用MStreamBuf::TellL()来检查文件指针是否已经到达 EOF .

下面代码展示了如何从流中读取多个整数知道EOF,所有的整数都被存放在一个数组中:

void CFileSteamAppUi::ReadAllTInt32FromStreamL(RFs& afs,const TDesC& aFileName, RArray& aArray)
{
//open the file stream.
RFileReadStream readStream;
User::LeaveIfError(readStream.Open(aFs, aFileName, EFileRead));
CleanuoClosePushL(readStream);


//Get the EOF position.
TStreamPos eofPos(readStream.Source()->SizeL());


//Get the current position of file pointer.
TStreamPos cuttentPos(0);


//Read all TInt32's until EOF
while(currentPos < eofPos)
{
TInt32 value;
readStream >> value;
aArray.Append(value);

currentPos = readStream.Source()->TellL(MStreamBuf::ERead);
}
CleanupStack::PopAndDestroy(&readStream);


}

你可能感兴趣的:(Symbian)