×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Unhappy Reading a file..

    Hai ppl...

    I am trying to read an Xml file.
    I hav been using RFileReadstream along with RFile.

    Bt the thing is i want the whole contents of the file in
    a single buffer(HBufC*)..i.e in a single read i should be able to extract the contents of the file without any looping,etc...

    Could anyone suggest me what to do????

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

    Re: Reading a file..

    And how did you try it earlier, and what actually went wrong with that approacj ?

  3. #3
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: Reading a file..

    Hi,

    You can use the following method. Here is the link

    or you can also use CParser to parse xml
    Use [URL="http://qt.nokia.com/products/qt-quick/"]Qt-Quick[/URL] to make your application UI more attractive.

    [URL="http://store.ovi.com/content/271896"]http://store.ovi.com/content/271896[/URL] | [URL="http://store.ovi.com/content/276199"]http://store.ovi.com/content/276199[/URL] |[URL="http://store.ovi.com/content/276202"] http://store.ovi.com/content/276202[/URL] | [URL="http://store.ovi.com/content/280827"]http://store.ovi.com/content/280827[/URL]

  4. #4
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156

    Re: Reading a file..

    This link may help you, try it out

    http://wiki.forum.nokia.com/index.ph..._CParser_class

  5. #5
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Re: Reading a file..

    Consider the following code....

    TInt iSize = read.Source()->SizeL();
    HBufC* buf = HBufC::NewL(read, iSize) ;
    TPtr16 pBuf = buf->Des() ;
    read >> pBuf;

    On execution....
    I m able to get the file size i.e iSize correctly(27 KB).
    In the next line i have passed it as a parameter...

    But when checked buf consisted only of 15 characters..It is reading only a little..and also the consecutive code too..
    Rather than going for loops can't i read it as a whole...

  6. #6
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Re: Reading a file..

    No..No...
    Consider the case of text file itself...
    Don't specialize for xml file..

  7. #7
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: Reading a file..

    Quote Originally Posted by deepchand86 View Post
    Consider the following code....

    TInt iSize = read.Source()->SizeL();
    HBufC* buf = HBufC::NewL(read, iSize) ;
    TPtr16 pBuf = buf->Des() ;
    read >> pBuf;

    On execution....
    I m able to get the file size i.e iSize correctly(27 KB).
    In the next line i have passed it as a parameter...

    But when checked buf consisted only of 15 characters..It is reading only a little..and also the consecutive code too..
    Rather than going for loops can't i read it as a whole...
    Hi,

    Not getting you exactly what you are trying to say. are you not able to read all the content of the file so just increase the file size let suppose make it double by multiply 2.
    Use [URL="http://qt.nokia.com/products/qt-quick/"]Qt-Quick[/URL] to make your application UI more attractive.

    [URL="http://store.ovi.com/content/271896"]http://store.ovi.com/content/271896[/URL] | [URL="http://store.ovi.com/content/276199"]http://store.ovi.com/content/276199[/URL] |[URL="http://store.ovi.com/content/276202"] http://store.ovi.com/content/276202[/URL] | [URL="http://store.ovi.com/content/280827"]http://store.ovi.com/content/280827[/URL]

  8. #8
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Re: Reading a file..

    No kkrish..

    I will be able to read the file if i construct a loop and use the above code...

    But my question is why can't i read it in a single call
    to HBufC constructor whose second argument is the file size i m going to read... But it is not reading the whole contents into the buffer...

    It's only reading a little into the buffer...
    Hope U Understand this....

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    444

    Re: Reading a file..

    Hi Deep,

    TInt iSize = read.Source()->SizeL();
    What is your "read" here?

    Also you can take the file size by using RFile::Size() method.

    Regards,
    Kavit.

  10. #10
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156

    Re: Reading a file..

    try to use this one by using RFile object
    TInt Read(TDes8 &aDes) const;

    you can read whole content of a file at a time into your TDes8 type object.

  11. #11
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Re: Reading a file..

    k mohanty...

    But while creating an TDes8 object..i need to mention the size..
    Am i right...

    Consider the case in which i m not sure abt the file size...
    Eventhough i get the Filesize...
    How do i create a Descriptor with that filesize dynamically???

  12. #12
    Registered User
    Join Date
    Nov 2007
    Posts
    444

    Re: Reading a file..

    For dynamic size you must have to use heap descriptors.
    That is HBuC.
    And you can get the file size as I mentioned above.
    This size can be used as the size parameter to create the heap descriptor.

    Regards,
    Kavit.

  13. #13
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156

    Re: Reading a file..

    Ya kavit is right.
    you go with him , you'll get result.

  14. #14
    Super Contributor
    Join Date
    Jul 2008
    Location
    Chennai,India
    Posts
    889

    Re: Reading a file..

    RFile myfile;
    RFs fss;
    User::LeaveIfError(fss.Connect());
    CleanupClosePushL(fss);
    User::LeaveIfError(myfile.Open(fss,KMyFile,EFileShareExclusive|EFileRead ));
    TInt size ;
    myfile.Size(size);


    HBufC8* buf = HBufC8::NewL(size) ;
    TPtr8 pBuf = buf->Des();
    myfile.Read(pBuf);


    I m using the above code to read the file.
    But it is aborting(No source available..) on the last line in the debug mode....
    (Read operation)....Any thing wrong in the above code...

  15. #15
    Regular Contributor
    Join Date
    Dec 2007
    Location
    Banglore,India
    Posts
    156

    Re: Reading a file..

    Quote Originally Posted by deepchand86 View Post
    RFile myfile;
    RFs fss;
    User::LeaveIfError(fss.Connect());
    CleanupClosePushL(fss);
    User::LeaveIfError(myfile.Open(fss,KMyFile,EFileShareExclusive|EFileRead ));
    TInt size ;
    myfile.Size(size);


    HBufC8* buf = HBufC8::NewL(size) ;
    TPtr8 pBuf = buf->Des();
    myfile.Read(pBuf);


    I m using the above code to read the file.
    But it is aborting(No source available..) on the last line in the debug mode....
    (Read operation)....Any thing wrong in the above code...



    you are correct in code, its running perfect for me.
    KMyFile is the path where your file exist,
    you check that path file is there or not
    Last edited by rkmohanty; 2008-08-04 at 10:54.

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
  •  
×