×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    26

    Write chinese words to the file.

    hi, my friends
    I write a program to put some Chinese words into the file. and I use the class RFile::write and RFile::flush to implement. But I meet a problem that is write function only get parameter of 8 bits, Chinese is composed 2 bytes. I don't know how to solve the problem.
    Thank you my friends!
    The belove is part of my code.
    _LIT(kbuf,"");
    TBuf<30> word(kbuf);
    TPtrC16 ptr16( word );
    //change the 16 to 8
    TBuf8<60> buf8;
    CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
    converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierCodePage1252, fs);
    User::LeaveIfError(converter->ConvertFromUnicode(buf8, ptr16));
    CleanupStack::PopAndDestroy(2); // fs, converter
    TInt suucess = buf8.Length();
    buf8[suucess+1 ] = ';';
    suucess= file->Write( buf8 );
    file->Flush();

  2. #2
    Regular Contributor
    Join Date
    Jan 2006
    Posts
    69

    Re: Write chinese words to the file.

    void CcontrolContainer::WriteInFile(TDesC& content,TDesC& filePath)
    {



    HBufC8* temp=HBufC8::NewL(content.Length());
    CleanupStack::PushL(temp);
    CnvUtfConverter::ConvertFromUnicodeToUtf8(temp->Des(),content);

    RFs iFs;
    iFs.Connect();
    CleanupClosePushL( iFs );
    RFile file;


    file.Open(iFs, filePath, EFileWrite);
    TInt Size;
    file.Size(Size);
    CleanupClosePushL( file );
    file.Write(Size,temp->Des());
    CleanupStack::PopAndDestroy();
    CleanupStack::PopAndDestroy();
    CleanupStack::PopAndDestroy();
    }

    这个方法可以在无数据损失情况下写入数据

  3. #3
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    Re: Write chinese words to the file.

    Or you could try something like this:

    void MyFunctions(const TDesC& aChineseText)
    {
    RFs iFs;
    iFs.Connect();
    CleanupClosePushL( iFs );
    RFile file;

    file.Open(iFs, filePath, EFileWrite);
    CleanupClosePushL( file );

    TPtrC8 Hjelp((TUint8 *)aChineseText->Ptr(),aChineseText.Size());

    file.Write(Hjelp);

    CleanupStack::PopAndDestroy();
    CleanupStack::PopAndDestroy();

    }

    yucca

Posting Permissions

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