Symbian3/SDK/Source/GUID-FA6E3270-C20A-5B05-9FFC-F3D4D8B35999.dita
changeset 0 89d6a7a84779
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/SDK/Source/GUID-FA6E3270-C20A-5B05-9FFC-F3D4D8B35999.dita	Thu Jan 21 18:18:20 2010 +0000
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
+<!-- This component and the accompanying materials are made available under the terms of the License 
+"Eclipse Public License v1.0" which accompanies this distribution, 
+and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
+<!-- Initial Contributors:
+    Nokia Corporation - initial contribution.
+Contributors: 
+-->
+<!DOCTYPE concept
+  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
+<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);
+if (err==KErrNotFound) // file does not exist - create it
+    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">
+// Open a file as text, writable, and shared with other clients
+RFile file;
+_LIT(KFileName, "FILENAME.CPP");
+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>
\ No newline at end of file