Read-only archive of the All About Symbian forum (2001–2013) · About this archive

Persistant Data Storage

1 replies · 1,805 views · Started 02 June 2004

Hi!

I am trying to write data to a file using RFile. However, whenever the program is executed on the emulator, it crashes as soon as the file is to be opened. Does anyone have any experiences with RFile?

RFs aFs;
RFile aFile;

_LIT(KFilename,"test.txt"😉; // Filename
_LIT8(KText,"Hello1"😉; // String to write into file test.txt

TInt err = aFile.Open(aFs, KFilename, EFileShareAny); // try to open file

if (err == KErrNotFound) // if file does not exist - create it
{
err = aFile.Create(aFs, KFilename, EFileShareAny);
}

err = aFile.Write(KText); // write String to file

aFile.Close(); // closing File

Thanks a lot in advance...

Maniac

Hi,

Try this code. You need to connect.


RFs aFs;
RFile aFile;

_LIT(KFilename,"test.txt"😉; // Filename

TBuf<128> buffer= _L("your content here"😉;
TBuf8<128> buf8;
buf8.Copy(buffer);

User::LeaveIfError(aFs.Connect());

TInt err = aFile.Open(aFs, KFilename, EFileWrite | EFileRead); // try to open file

if (err == KErrNotFound) // if file does not exist - create it
{
err= aFile.Create(aFs, KFilename, EFileWrite | EFileRead);
}

aFile.Write(buf8);

aFile.Close(); // closing File

Bye
rmm