00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // This example writes the text "hello world!" to a file 00015 // Use it as the basis of all examples which depend on just E32 and F32 00016 // 00017 00018 #include "CommonFramework.h" 00019 #include <f32file.h> 00020 00021 _LIT(KFileName,"WriteToFile.dat"); 00022 _LIT(KGreetingText,"Hello World!\n"); 00023 00024 // Do the example 00025 static void doExampleL() 00026 { 00027 // The file server session. 00028 RFs fsSession; 00029 // Connect to the file server session. 00030 User::LeaveIfError(fsSession.Connect()); 00031 00032 // create the private directory 00033 // on the writable drive 00034 // i.e. "\private\0FFFFF00\" 00035 // Note that the number 0FFFFF00 is the 00036 // process security id taken from the 2nd UID 00037 // specified in the mmp file. 00038 00039 fsSession.CreatePrivatePath(RFs::GetSystemDrive()); 00040 // Set the session path to 00041 // this private directory on the writable drive 00042 fsSession.SetSessionToPrivate(RFs::GetSystemDrive()); 00043 00044 // Use this object to represent 00045 // the file to be written to. 00046 RFile file; 00047 00048 User::LeaveIfError(file.Replace(fsSession,KFileName,EFileWrite|EFileStreamText)); 00049 00050 00051 // Note that Write() requires a TDesC8 00052 // type so we need to construct an explicit 00053 // TDesC8 type to represent the data contained 00054 // in the standard (16-bit) descriptor. 00055 TPtrC8 representation((TUint8*)(&KGreetingText)->Ptr(), (&KGreetingText)->Size()); 00056 00057 // Write the text ... 00058 User::LeaveIfError(file.Write(representation)); 00059 00060 // ... and commit the text. 00061 User::LeaveIfError(file.Flush()); 00062 00063 _LIT(KTxt1,"Data written to file\n"); 00064 console->Printf(KTxt1); 00065 // Close file 00066 file.Close(); 00067 // Delete file (remove comment if you want 00068 // to do this) 00069 //User::LeaveIfError(fsSession.Delete(KFileName)); 00070 00071 // close file server session 00072 fsSession.Close(); 00073 }