Symbian文件操作笔记

创建一个文件夹并且在这个文件夹中创建一个文件,写入一些数据

_LIT( KFileDir, "//DyEye//");
_LIT( KFileNames, "Shi.txt" );

TInt err;
 TInt objectInStack = 1;
 TBuf<64> text;
 RFs fs;
 User::LeaveIfError(fs.Connect());
 CleanupClosePushL(fs);
 err = fs.MkDir(KFileDir);
 if( KErrNone != err)
  {
   _LIT(KMkDirFail,"MkDir is Fail %S, err = %d, del folder and retry");
   CAknWarningNote* dlg = new(ELeave)CAknWarningNote;
   text.Format(KMkDirFail,&KFileDir ,err);
   dlg->ExecuteLD(text);
   CleanupStack::PopAndDestroy(objectInStack);
   return;
  }
 objectInStack += 1;
 TFileName path;
 path.Append(KFileDir);
 fs.SetSessionPath(path);
 
 RFile file;
 err = file.Replace(fs,KFileNames,EFileRead|EFileWrite);
 CleanupClosePushL(file);
 if( KErrNone != err)
  {
  _LIT(KCreateFileFail,"CreateFile is fail %S, err = %d");
  text.Format(KCreateFileFail,&KFileNames,err);
  CAknWarningNote* dlg1 = new(ELeave)CAknWarningNote;
  dlg1->ExecuteLD(text);
  CleanupStack::PopAndDestroy(objectInStack);
  return;
  }
 objectInStack += 1;
 RFileWriteStream stream(file);
 CleanupClosePushL(stream);
 _LIT(KText,"Shi Test");
 stream<<KText;
 
 
 CleanupStack::PopAndDestroy(objectInStack);

你可能感兴趣的:(Stream,File,user,Path,Symbian)