×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    9

    Reading from binary file, how to manage file ending?

    Hello!!

    I need to read some binarydata from file where I have stored it before. I have used FileReadStream stream to read data, but I haven't solve how to make endcondition like that the read ends in the end of the file without errors. My code looks like this now:

    RFs fsSession;
    User::LeaveIfError(fsSession.Connect());
    CleanupClosePushL( fsSession );

    TInt err = fsSession.MkDirAll(KFileName);
    if ( (KErrNone != err) && (KErrAlreadyExists != err) )
    {
    CleanupStack::PopAndDestroy(); // fsSession
    return NULL;
    }

    RFile file;
    err = file.Open(fsSession, KFileName, EFileRead );
    CleanupClosePushL( file );
    if ( KErrNone != err )
    {
    CleanupStack::Pop();
    }
    TInt size;
    file.Size(size);

    RFileReadStream inputFileStream( file );
    CleanupClosePushL( inputFileStream );
    TInt error=KErrNone;
    TInt index=0;
    do
    {
    TRAP( err, inputFileStream>>buf );
    if (err==KErrNone)
    {
    locationInfo->SetName( buf );
    }
    TRAP( err, inputFileStream>>longitude );
    if (err==KErrNone)
    {
    locationInfo->SetLong( longitude );
    }
    TRAP( err, inputFileStream>>latitude );
    if (err==KErrNone)
    {
    locationInfo->SetLat( latitude );
    locationArray->AppendL(locationInfo, index);
    }
    index++;
    }
    while( err!=KErrEof );
    inputFileStream.Close();
    file.Close();
    fsSession.Close();
    CleanupStack::PopAndDestroy(3);

    This falls when we get the file end. If someone knows what have to be the endcondition please help me! Thank you all ready!!

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,169

    Re: Reading from binary file, how to manage file ending?

    have you just tried the RFile, and its Read function variants that allow you to specify the excat lenght to be read.

  3. #3
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Bangalore
    Posts
    91

    Re: Reading from binary file, how to manage file ending?

    RFile::Size() should help.
    Cheers
    Subhasis

Similar Threads

  1. Replies: 15
    Last Post: 2011-08-18, 12:37
  2. Replies: 13
    Last Post: 2007-12-07, 11:21
  3. After writing file in binary format the file is reable
    By Rajani_sp in forum Symbian User Interface
    Replies: 6
    Last Post: 2007-11-22, 15:37
  4. Replies: 1
    Last Post: 2005-05-26, 14:22
  5. Replies: 0
    Last Post: 2002-06-10, 12:24

Posting Permissions

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