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

来源:互联网 发布:csgo启动项优化 编辑:程序博客网 时间:2024/06/06 04:04
检测文件流结尾
调用MStreamBuf::SizeL()来获取文件的大小,然后调用MStreamBuf::TellL()来检查文件指针是否已经到达 EOF .

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

void CFileSteamAppUi::ReadAllTInt32FromStreamL(RFs& afs,const TDesC& aFileName, RArray<TInt>& 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);


}

原创粉丝点击