Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to read and write a file

Reading transfers data from a file to a descriptor, and writing transfers data from a descriptor to a file.

Use RFile::Read() to read, and RFile::Write() to write.

// Open file1
_LIT(KMyFile,"c:\\documents\\file1");
RFile myFile;
User::LeaveIfError(myFile.Open(fs,KMyFile,EFileShareExclusive|EFileWrite
));

// Write to current file position: start of file
_LIT8(KWriteBuf,"write data");
myFile.Write(KWriteBuf);

// Read from position 0: start of file
TBuf8<6> readBuf1;
myFile.Read(0,readBuf1); // readBuf1 is now "write "

// Read from current position
TBuf8<4> readBuf2;
myFile.Read(readBuf2);    // readBuf2 is now "data"

[Top]


Notes