×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    Cairo, Egypt
    Posts
    29

    How can I write binary values using RFile?

    Hi all,

    I want to write binary values in a file using RFile.

    Example:

    when I fill a buffer (HBufC8*) with some nulls mixed with another values
    "0065000000", plus I have determined the number of bytes which will be written, It panics !


    /*Code */

    char tempChar4Bytes[4];
    int integerValue = 56845;

    tempChar4Bytes[0] = 0x000000FF & integerValue ;
    tempInteger = integerValue >> 8;
    tempChar4Bytes[1] = tempInteger;
    tempInteger = integerValue >> 16;
    tempChar4Bytes[2] = 0x000000FF & tempInteger;
    tempInteger = integerValue >> 24;
    tempChar4Bytes[3] = 0x000000FF & tempInteger;

    /* HBufC8 */
    tempHeap->Des().Copy((unsigned char const*)tempChar4Bytes);

    /* TPtr8 */
    tempPtr.Set(tempHeap->Des());

    /* RFile */
    OutputFile.Write(tempPtr,4);

    So, how can I write binary values using RFile?

    Thanks,

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: How can I write binary values using RFile?

    lI would do it like this:
    const TInt32 value = 56845;
    const TPckgC<TInt32> pkg(value);
    OutputFile.Write(pkg);

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    Cairo, Egypt
    Posts
    29

    Re: How can I write binary values using RFile?

    Thanks, it works fine... but what is the solution if I want to write a "short int" array (binary) in a file?

    Thank you,

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: How can I write binary values using RFile?

    You can use TPtrC8/TPtr8 for that:
    Code:
    TUint16 a[10];
    TPtrC8 aPack((TUint8 *)&a[0],20);
    file.Write(aPack);
    or you can still put the array into a T-class, and use TPckg.

  5. #5
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: How can I write binary values using RFile?

    Personally I am more in favour of using RFileWriteStream to write out blobs of basic data. TPckg(C) are useful when you want to write out a T structure easily

    Through the use of google (www.google.com) you can find plenty of examples on using RFileWriteStream.

  6. #6
    Registered User
    Join Date
    Aug 2007
    Location
    Cairo, Egypt
    Posts
    29

    Re: How can I write binary values using RFile?

    Thank you all for your help

Similar Threads

  1. RFile Read Write Asynchronous KErrCorrupt
    By muntain in forum Symbian
    Replies: 21
    Last Post: 2010-04-22, 11:03
  2. RFile write
    By mabdulmoniem in forum Symbian
    Replies: 6
    Last Post: 2008-12-23, 13:02
  3. write and read binary data to file
    By sunny_singh in forum Symbian
    Replies: 0
    Last Post: 2005-10-18, 10:01
  4. Replies: 3
    Last Post: 2005-08-01, 13:39
  5. Loading images from byte array on 6130i
    By enlightment in forum Mobile Java General
    Replies: 2
    Last Post: 2002-06-05, 19:44

Posting Permissions

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