×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Aug 2007
    Location
    India
    Posts
    83

    How to Handle TFileText class..

    Hi all,
    i am beginner to Symbian.

    I would like to read a simple text file in my program.
    line by line i need to read.

    i am using TFileText class--is it ok??
    Do i need to create any File session object.

    pls give me Any simple code..

    Regards,
    Pavan.

  2. #2
    Regular Contributor
    Join Date
    Dec 2007
    Location
    India
    Posts
    155

    Re: How to Handle TFileText class..

    Quote Originally Posted by Tatavarthi View Post
    Hi all,
    i am beginner to Symbian.

    I would like to read a simple text file in my program.
    line by line i need to read.

    i am using TFileText class--is it ok??
    Do i need to create any File session object.

    pls give me Any simple code..

    Regards,
    Pavan.
    Hi use this code for read a text file.

    _LIT(KFileSpec,"C:\\Test.txt");
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    RFile ifile;
    TInt iErr1=file.Open(fs,KFileSpec,EFileRead);
    if(iErr1==KErrNone)
    {
    TInt iSize;
    file.Size(iSize);
    HBufC8* buffer = HBufC8::NewLC(iSize);
    TPtr8 ptr= buffer->Des();
    file.Read(ptr);
    file.Close();
    CleanupStack::PopAndDestroy(buffer);
    }
    fs.Close();
    CleanupStack::PopAndDestroy(&fs);

    And if u want read through TFileText class then chk this link..
    http://wiki.forum.nokia.com/index.ph...ead_a_CSV_file


    regards
    Md.kashif

  3. #3
    Super Contributor
    Join Date
    Jan 2008
    Location
    Bangalore, India
    Posts
    777

    Re: How to Handle TFileText class..

    Quote Originally Posted by Tatavarthi View Post
    Hi all,
    i am beginner to Symbian.

    I would like to read a simple text file in my program.
    line by line i need to read.

    i am using TFileText class--is it ok??
    Do i need to create any File session object.

    pls give me Any simple code..

    Regards,
    Pavan.
    TFileText class is only for Single line read/write operation.
    so if ur file is having a single line.and before use it you have to create your file session.
    after creating the file session you have to use its Set(RFile &aFile).
    then u can read ur file line by line.
    by using this
    Read(TDes &aDes);

    ur desc will hold single line text.
    if u use seek() method as ESeekStart then ur read operation begins at the current file position, and ends when a line delimiter character is read.
    ur record can not exceed length of 256 characters.
    Regards
    $-Nitesh-$

  4. #4
    Regular Contributor
    Join Date
    Aug 2007
    Location
    India
    Posts
    83

    Re: How to Handle TFileText class..

    Hi kasif,

    Here i am getting error.
    i am giving code pls go through it..

    void ProcessList(TDes8* aBuffer)
    {

    TBuf<256> res;
    TFindProcess findP;
    aBuffer->Zero();

    _LIT(KFileSpec,"C:\\Test.txt");

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

    RFile ifile;
    TInt iErr1=ifile.Open(fs,KFileSpec,EFileRead);
    //HBufC8 buffer;
    //TBuf<8> buf1;
    //TPtr8 ptr2(buf1.Des());
    if(iErr1==KErrNone)
    {

    TInt iSize;
    ifile.Size(iSize);
    HBufC8* buffer = HBufC8::NewLC(iSize);
    TPtr8 ptr= buffer->Des();
    // buf1 = ptr;
    ifile.Read(ptr);
    //ptr2.Set(ptr);
    ifile.Close();
    CleanupStack::PopAndDestroy(buffer);

    }

    //Get only the first five processes, otherwise it goes on for ages!
    for(TInt i = 0; i < 5; i++)
    {
    findP.Next(res);
    //check that we are not overflowing aBuffer
    if( (aBuffer->Size() + res.Size()) < 256 )
    {

    aBuffer->Append(buffer);// Here i am getting buffer undeclared error
    }
    else
    {
    break;
    }
    }

    fs.Close();
    CleanupStack::PopAndDestroy(&fs);
    //while(FP.Next(res)==KErrNone) { aBuffer->Append(res); aBuffer->Append(KSpace); }
    }


    i am sorry if my approch is incorrect...i am beginner boss..

    Regards,
    Pavan

  5. #5
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: How to Handle TFileText class..

    "i am giving code pls go through it.."

    You might only be a beginner, but why can't you go through it yourself?

    Is it really that difficult to just try and think a tiny bit what the problem could be? Even if you don't know SYmbian very well you must know how to program in some other language?

    Give it a try for yourself - you said you are getting buffer undeclared error, so is that a compiler error? If so then what can that mean, it can only mean the compiler doesn't recognize the variable called buffer. So why not have a look back up your code to see if buffer is there and if it is already there does where it is mean the compiler can't see it where you are using it?
    Last edited by hotcheese; 2008-03-07 at 18:27.

Similar Threads

  1. Issue when trying to generate .sis file
    By rmulam in forum Symbian Tools & SDKs
    Replies: 9
    Last Post: 2009-08-13, 14:10
  2. Java Application running on WTK but not on S60 SDK
    By roman.benz in forum Mobile Java Tools & SDKs
    Replies: 6
    Last Post: 2009-06-09, 14:38
  3. how to handle send() function in CBluetoothSynchronousLink class
    By hasiamar in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2008-04-24, 07:44
  4. Container Class needs help
    By vinayashrestha in forum Symbian User Interface
    Replies: 3
    Last Post: 2007-11-14, 12:54
  5. Replies: 0
    Last Post: 2003-12-07, 16:06

Posting Permissions

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