equal
deleted
inserted
replaced
|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept xml:lang="en" id="GUID-FA6E3270-C20A-5B05-9FFC-F3D4D8B35999"><title>How to create and open a file</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>The <xref href="GUID-BE0804F6-4375-3C8A-8C83-968F510466E0.dita"><apiname>RFile</apiname></xref> interface is used to create, open, read from and write to a single file. </p> <section><title>Creating and opening a file</title> <p>A common pattern is to attempt to open an existing file, without replacing its existing data, and create it if it does not exist. </p> <ol id="GUID-42702312-C0C9-5788-8819-4BB5730320B5"><li id="GUID-31FFB1C8-AB53-581B-835E-0C33839CEEA5"><p>Use <codeph>Open()</codeph> to open an existing file for reading or writing - an error is returned if it does not already exist. </p> </li> <li id="GUID-9CC8F1EA-196E-5A77-AA80-9BBA198C3B62"><p>Use <codeph>Create()</codeph> to create and open a new file for writing. </p> </li> </ol> <codeblock id="GUID-70C09A68-4C30-5766-99C5-D9BF23ADC85F" xml:space="preserve">TInt err=file.Open(fsSession,fileName,shareMode); |
|
13 if (err==KErrNotFound) // file does not exist - create it |
|
14 err=file.Create(fsSession,fileName,shareMode);</codeblock> </section> <section><title>Specifying a share and access mode</title> <p>Use various flags to specify how a file is opened. </p> <codeblock id="GUID-44FB8760-7C13-503D-A53A-3DF794768D26" xml:space="preserve"> |
|
15 // Open a file as text, writable, and shared with other clients |
|
16 RFile file; |
|
17 _LIT(KFileName, "FILENAME.CPP"); |
|
18 file.Open(fsSession,KFileName,EFileStreamText|EFileWrite|EFileShareAny);</codeblock> <p><b>Notes</b> </p> <ul><li id="GUID-6124BD90-9267-523E-BC8E-590BED022083"><p>If another <codeph>RFile</codeph> object tries to open this file in <codeph>EFileShareExclusive</codeph> or <codeph>EFileShareReadersOnly</codeph> mode, access is denied. It can only be accessed in <codeph>EFileShareAny</codeph> mode. </p> </li> <li id="GUID-45948CEF-7780-51E4-B862-F7A8A5983EE5"><p>If a file is not closed explicitly (using <codeph>RFile::Close()</codeph>), it will be closed when the server session associated with it is closed. </p> </li> </ul> </section> </conbody></concept> |