A problem about file reading

Login to reply to this topic.
Wed, 2007-06-20 08:17
Joined: 2007-06-20
Forum posts: 26

I used RFile and TFileText to find a line that contains some keywords in a file.

The code is:


TPtrC strValue;
HBufC* str = HBufC::NewLC(50);
CleanupStack::PushL(str);
RFs fs;
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
RFile file;
User::LeaveIfError(file.Open(fs, filePath, EFileRead));
TFileText tfile;
tfile.Set(file);
TBuf<1024> buf;
tfile.Seek(ESeekStart);

while (tfile.Read(buf) == KErrNone)
{
 if (buf.Find(MainKey) >= 0)
 {
  strValue.Set(buf);
  str = strValue.AllocL();
 }
}
file.Close();
CleanupStack::PopAndDestroy();
CleanupStack::PopAndDestroy(str);

After the line "file.Close()" was executed, the program couldn't go further. What's the problem?


Wed, 2007-06-20 08:42
Joined: 2005-02-11
Forum posts: 214
Re: A problem about file reading

You don't have to push HBufC anymore. NewLC means that it is already in cleanupstack

HBufC* str = HBufC::NewLC(50);
CleanupStack::PushL(str); //Not needed


"I only know that I know nothing." (Socrates)

Thu, 2007-06-21 08:03
Joined: 2007-06-20
Forum posts: 26
Re: A problem about file reading

Thanks for your reply. My problem has been solved.

  • Login to reply to this topic.