×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Jul 2004
    Posts
    201

    write and read a TInt data from the file

    How to write and read a TInt data from the file with symbian c++ code.

    I want to write a TInt data to a file, then read the data from the file with c++.

    My code below, but them error, who can tell me how to do that,thank you very much.


    // Open file1
    TInt tiDay;
    tiDay = 1;
    RFs fs;
    TInt err;
    fs.Connect();
    _LIT(KMyFile,"c:\\file1");
    RFile myFile;
    //myFile.Open(fs,KMyFile,EFileShareExclusive|EFileWrite);
    err = myFile.Open(fs,KMyFile,EFileShareExclusive|EFileWrite);
    if (err == KErrNotFound) // file does not exist - create it
    {
    err=myFile.Create(fs,KMyFile,EFileShareExclusive|EFileWrite);
    // Write to current file position: start of file
    _LIT8(KWriteBuf,tiDay);
    myFile.Write(KWriteBuf);

    }

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

    TLex8 tlexData(readBuf1);
    err = tlexData.Val(tiFromFile);
    fs.Close();

    I hope that take tiDay to file, then read it from the file.

    Who can teach me.

    Thank you very much.

  2. #2
    Regular Contributor
    Join Date
    Jul 2004
    Posts
    201

    who know it

    who know it?

  3. #3
    Nokia Developer Expert
    Join Date
    Apr 2003
    Location
    Finland
    Posts
    425
    Code:
            CDictionaryStore* iniFile = Application()->OpenIniFileLC(iEikonEnv->FsSession());
            RDictionaryWriteStream writeStream;
            writeStream.AssignLC(*iniFile, Application()->AppDllUid());
    
            writeStream.WriteInt16L( 0x666 );
    
            writeStream.CommitL();
            writeStream.Release();
    
            CleanupStack::PopAndDestroy(&writeStream);
    
            iniFile->CommitL();
            CleanupStack::PopAndDestroy(iniFile);
    Code:
        CDictionaryStore* iniFile = Application()->OpenIniFileLC (iEikonEnv->FsSession());
        RDictionaryReadStream readStream;
    
        readStream.OpenLC (*iniFile,Application()->AppDllUid());
    
        badNumber = readStream.ReadInt16L();
    
        readStream.Close();
    
        CleanupStack::PopAndDestroy(&readStream); 
        CleanupStack::PopAndDestroy(iniFile);
    Br V

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×