diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/PDK/Source/GUID-FA6E3270-C20A-5B05-9FFC-F3D4D8B35999.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/PDK/Source/GUID-FA6E3270-C20A-5B05-9FFC-F3D4D8B35999.dita Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,18 @@ + + + + + +How to create and open a file

The RFile interface is used to create, open, read from and write to a single file.

Creating and opening a file

A common pattern is to attempt to open an existing file, without replacing its existing data, and create it if it does not exist.

  1. Use Open() to open an existing file for reading or writing - an error is returned if it does not already exist.

  2. Use Create() to create and open a new file for writing.

TInt err=file.Open(fsSession,fileName,shareMode); +if (err==KErrNotFound) // file does not exist - create it + err=file.Create(fsSession,fileName,shareMode);
Specifying a share and access mode

Use various flags to specify how a file is opened.

+// Open a file as text, writable, and shared with other clients +RFile file; +_LIT(KFileName, "FILENAME.CPP"); +file.Open(fsSession,KFileName,EFileStreamText|EFileWrite|EFileShareAny);

Notes

  • If another RFile object tries to open this file in EFileShareExclusive or EFileShareReadersOnly mode, access is denied. It can only be accessed in EFileShareAny mode.

  • If a file is not closed explicitly (using RFile::Close()), it will be closed when the server session associated with it is closed.

\ No newline at end of file