Problem write data to file with RFileWriteStream ! Please help me ! Thanks!

Login to reply to this topic.
Thu, 2006-03-16 09:22
Joined: 2005-06-21
Forum posts: 107
Hi all !
I want to write data from file a.txt to b.txt by using "RFileWriteStream" and "RFileReadStream".But data doesn't write into b.txt file . Please help me to correct my code ! Thanks very much !.
//=============  This is my code ========
void CView01::WriteData()
{
      //=====   Connect to File server
      RFs aFs;
      User::LeaveIfError(aFs.Connect());
      CleanupClosePushL(aFs);
      _LIT( Filepath02, "C:\\b.txt");
      _LIT( Filepath01, "C:\\a.txt");

      //=====  Object for reading stream
      RFileReadStream fRead;
      //=====   Open a read stream
      User::LeaveIfError(fRead.Open(aFs, Filepath01, EFileRead));
      TInt8 pBuf1 = fRead.ReadInt8L();
      TInt8 pBuf2 = fRead.ReadInt8L();
      TInt8 pBuf3 = fRead.ReadInt8L();

      //=====   Write to File
      RFileWriteStream fWrite;
      //=====   Open a write stream
      User::LeaveIfError(fWrite.Create( aFs, Filepath02, EFileWrite ) );
      fWrite.WriteInt8L(pBuf1);
      fWrite.WriteInt8L(pBuf2);
      fWrite.WriteInt8L(pBuf3);

     CleanupStack::PopAndDestroy(&aFs);

}
//=========== doctinh113114===========

Thu, 2006-03-16 17:26
Joined: 2005-03-14
Forum posts: 59
Re: Problem write data to file with RFileWriteStream ! Please he
use separate RFs for read and write maybe?
Mon, 2006-03-20 13:39
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2009
Re: Problem write data to file with RFileWriteStream ! Please he
Don't use separate RFs!!!
Call fWrite.CommitL() to ensure data are written on disk (or fWrite.Close() if you don't need it anymore).

Note also that you should push fRead and fWrite on the cleanup stack and destroy them before before destroying your RFs session.

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

  • Login to reply to this topic.