×

Discussion Board

Results 1 to 4 of 4

Thread: Reading a file

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    36

    Reading a file

    Hi ,

    I am trying to read a file in chuncks.i am using the following code...

    HBufC8* buffer = HBufC8::NewL( 8192 );
    TPtr8 ptr = buffer->Des();
    if(cnt == 0)
    {
    CleanupClosePushL(file);
    file.Read(ptr,8192); CleanupStack::PopAndDestroy(1);
    }
    else
    {
    TInt32 pos = cnt*8192;
    CleanupClosePushL(file);
    TInt st = file.Read(pos,ptr,8192); CleanupStack::PopAndDestroy(1);
    }

    //doing some operation here with ptr

    It gives me error at the bold line that no source code available and closes the application.

    Can someone help me out ?

    Regards

  2. #2
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: Reading a file

    Quote Originally Posted by kumar_a View Post
    Hi ,

    I am trying to read a file in chuncks.i am using the following code...

    HBufC8* buffer = HBufC8::NewL( 8192 );
    TPtr8 ptr = buffer->Des();
    if(cnt == 0)
    {
    CleanupClosePushL(file);
    file.Read(ptr,8192);
    CleanupStack::PopAndDestroy(1);
    }
    else
    {
    TInt32 pos = cnt*8192;
    CleanupClosePushL(file);
    TInt st = file.Read(pos,ptr,8192);
    CleanupStack::PopAndDestroy(1);
    }

    //doing some operation here with ptr

    It gives me error at the bold line that no source code available and closes the application.

    Can someone help me out ?

    Regards
    Since the Read method is not expected to leave the use of the cleanup stack above is not needed. You may want to add the file to the cleanup stack immediately after opening it and certainly before the call to BufC8::NewL which, as it's name indicate, may indeed leave.

    Now, aside from the cleanup stack misuse, could you indicate what error you are in fact getting? What is the value of st or what panic occurs?

    Also, when cnt is 0, pos = cnt*8192 = 0 too so you don't really need that if fork in your code, just use the else branch all the time.
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: Reading a file

    My guess would be that you use this snippet in a loop.
    First time cnt=0, so the cnt == 0 block is running: pushes the file onto the Cleanup Stack, reads data, PopAndDestroy removes the file from the Cleanup Stack and closes it
    Next time cnt!=0, so the else block is running: pushes the file onto the Cleanup Stack, tries to read some data from an already closed file, and panics due to this tiny fact.

    Also note that RFile has an actual position, so if you do not want to close the file between the reads, file.Read(ptr,8192) will read the 2nd 8192 bytes of the file on the 2nd time, etc.

    Enabling panic codes is here: http://wiki.forum.nokia.com/index.ph...ded_panic_code .
    And panics usually appear in both the output window of the debugger and the emulator logfile (http://wiki.forum.nokia.com/index.php/Epocwind.out).

  4. #4
    Super Contributor
    Join Date
    Jan 2007
    Location
    Bhubaneswar, India
    Posts
    1,189

    Re: Reading a file

    -------------------------------------
    Thanks & Regards
    Ram
    Symbian OS 9.2/9.3,S60 3rd FP1/FP2,Carbide.c++v2.0

Similar Threads

  1. Problem with pyobfuscate
    By JOM in forum Symbian
    Replies: 3
    Last Post: 2008-06-20, 22:47
  2. problem when importing from carbide c++ to vs 2003!
    By misfit.physics in forum Symbian Tools & SDKs
    Replies: 12
    Last Post: 2008-02-19, 09:45
  3. creating list box error reading from file
    By pulkitjain in forum Symbian
    Replies: 2
    Last Post: 2008-01-26, 05:23
  4. Replies: 2
    Last Post: 2007-12-28, 15:53

Posting Permissions

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