Discussion Board

Results 1 to 13 of 13
  1. #1
    Regular Contributor aluzi's Avatar
    Join Date
    Mar 2008
    Posts
    77
    File is create with RFile.Write() function, it's content is plain text. I want to read this file line by line, just like a "StreamReader.ReadLine()" funtion in C#. But RFile class does not offers such function....

  2. #2
    Regular Contributor Tatavarthi's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    83
    Hope this will helps you!

    _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
    Last edited by Tatavarthi; 2008-03-25 at 06:22. Reason: now go through it!

  3. #3
    Nokia Developer Moderator ltomuta's Avatar
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,335
    Look for TFileText in SDKs docs. Mind you that the line length is restricted to 256 characters.

  4. #4
    Regular Contributor aluzi's Avatar
    Join Date
    Mar 2008
    Posts
    77
    Quote Originally Posted by Tatavarthi View Post
    Hope this will helps you!

    _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

    But if my text file very large, HBufC8* buffer = HBufC8::NewLC(iSize) still can work?

  5. #5
    Nokia Developer Champion Nitesh Bhardwaj's Avatar
    Join Date
    Jan 2008
    Location
    Bangalore, India
    Posts
    777
    Quote Originally Posted by aluzi View Post
    But if my text file very large, HBufC8* buffer = HBufC8::NewLC(iSize) still can work?
    yes it ll work.

  6. #6
    Regular Contributor Tatavarthi's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    83
    Quote Originally Posted by aluzi View Post
    But if my text file very large, HBufC8* buffer = HBufC8::NewLC(iSize) still can work?
    Yes i think it should work!
    Myself i used it with around 1 MB JPEG image which is in text form.

    -Regards,
    Pavan

  7. #7
    Regular Contributor aluzi's Avatar
    Join Date
    Mar 2008
    Posts
    77
    Quote Originally Posted by ltomuta View Post
    Look for TFileText in SDKs docs. Mind you that the line length is restricted to 256 characters.
    Thanks! I try it and it really wotk.

    Another question, I write some CHINESE string to file using TFileText.Write(), And then I TFileText.Read() this string and display using iEikonEnv->InfoMsg(), the CHINESE string can display correctlly. But when I open the file in Windows Explorder using notepad, I can't read it's contents at all!

  8. #8
    Registered User szhkazmi's Avatar
    Join Date
    Mar 2008
    Posts
    21
    im trying to open file but it is not working, there is some unhandled exception in the TRAPD, here is my code please tell me whats the problem with it:

    void CompressImage::Compress( const TDesC& aFilePath )
    {

    TInt FileSize;
    RFs ServerObj;
    ServerObj.Connect();

    TRAPD(error, iFile.Open( ServerObj, aFilePath, EFileRead) );

    if(error!=KErrNone)
    {
    CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
    TBuf<100> msg;
    msg.AppendNum(error);
    informationNote->ExecuteLD(msg);
    }

    iFile.Size( FileSize );

    HBufC8* newbuff;
    HBufC8* buff = NULL;
    buff = HBufC8::NewL( FileSize );
    TBuf8<256> t1;
    TBuf8<256> t2;

    iFile.Read( t1 );
    CExifModify* ExifObj = CExifModify::NewL( t1 );
    ExifObj->SetXResolutionL( 10, 10 );
    ExifObj->SetYResolutionL( 20, 20 );

    newbuff = ExifObj->WriteDataL( t2 );
    iFile.Create( ServerObj, _L("c:\\Data\\Images\\BlueFlower.bmp"), EFileWrite );
    iFile.Write( *newbuff );
    iFile.Close();

    iReader->NewL();
    iReader->PrepareImageL( aFilePath );
    iReader->Bitmap();
    iCompressed = ETrue;
    };

  9. #9
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    27,680
    First of all, RFile::Open is not "OpenL", thus TRAP/D does not do anything to it. Try
    Code:
    TInt error=iFile.Open(...);

  10. #10
    Registered User szhkazmi's Avatar
    Join Date
    Mar 2008
    Posts
    21
    i have tried;
    TInt error = iFile.Open( ServerObj, aFilePath, EFileRead);

    here is my code:
    TInt FileSize;
    RFs ServerObj;
    ServerObj.Connect();

    TBuf<100> msg;
    CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
    informationNote->ExecuteLD( aFilePath );

    TInt error = iFile.Open( ServerObj, aFilePath, EFileRead);
    msg.Num(error);
    informationNote->ExecuteLD(msg);
    ......................................................

    But is still it is not working, neither the error value is getting displayed.

  11. #11
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    27,680
    If you want to have the error code displayed, use
    Code:
    User::LeaveIfError(iFile.Open( ServerObj, aFilePath, EFileRead));

  12. #12
    Registered User szhkazmi's Avatar
    Join Date
    Mar 2008
    Posts
    21
    Thank you for being so helpful! now im trying to change the resolution of .jpg file, everything is working fine but the application gets closed at this line"CExifModify* ExifObj = CExifModify::NewL( t1 );" , here is my code;

    TInt FileSize;
    RFs ServerObj;
    ServerObj.Connect();
    RFile zf1;
    zf1.Open( ServerObj, aFileName, EFileRead);
    zf1.Size( FileSize );
    HBufC8* newbuff;
    HBufC8* buff = NULL;
    buff = HBufC8::NewL( FileSize );

    TBuf8<7567> t1;
    zf1.Read( t1 );
    /* here */
    CExifModify* ExifObj = CExifModify::NewL( t1 );
    ExifObj->SetXResolutionL( 10, 10 ); ExifObj->SetYResolutionL( 20, 20 );
    newbuff = ExifObj->WriteDataL( t1 );

    zf1.Close();
    zf1.Create( ServerObj, _L("c:\\Data\\Images\\myfile.jpg"), EFileWrite ); //Replacing the file
    zf1.Write( *newbuff );
    zf1.Close();
    ServerObj.Close();


    thanks again!!!

  13. #13
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    27,680
    Have you enabled extended panic codes? http://wiki.forum.nokia.com/index.ph...ded_panic_code

Similar Threads

  1. i cant build helloworld project
    By akhin in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2008-12-22, 12:38
  2. Replies: 3
    Last Post: 2007-03-07, 03:36
  3. Read text file line by line
    By fdelvalle in forum Symbian C++
    Replies: 5
    Last Post: 2007-01-31, 09:48
  4. Replies: 1
    Last Post: 2005-05-26, 14:22
  5. How can i read a large text in resource file?
    By MyDear in forum Symbian C++
    Replies: 0
    Last Post: 2004-03-28, 06:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved