×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    227

    How to write to file (with the last write on the top)

    Hi, I want to make debug / log file, but I want to write it with the last write on the top of the file.
    How to do that?

    Thanks

  2. #2
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,004

    Re: How to write to file (with the last write on the top)

    Using RFile ::TInt Write(TInt aPos, const TDesC8 &aDes);, you can specify aPos to be 0. If that doesn't suits your requirement then RFile::Seek() may also be used & then write to file.

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,173

    Re: How to write to file (with the last write on the top)

    RFile::Write(TInt aPos, const TDesC8 &aDes, TInt aLength) can help you. Try giving the value of aPos as 0.

    EDIT: Sorry, I just posted without having a refresh of page. So, duplicate answer.

  4. #4
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    227

    Re: How to write to file (with the last write on the top)

    Quote Originally Posted by vineet.jain View Post
    Using RFile ::TInt Write(TInt aPos, const TDesC8 &aDes);, you can specify aPos to be 0. If that doesn't suits your requirement then RFile::Seek() may also be used & then write to file.
    Thanks for your answer vineet, I will try it

    Quote Originally Posted by pooja_1650 View Post
    RFile::Write(TInt aPos, const TDesC8 &aDes, TInt aLength) can help you. Try giving the value of aPos as 0.

    EDIT: Sorry, I just posted without having a refresh of page. So, duplicate answer.
    Nevermind pooja, two answer is better than one )
    thanks for your answer

  5. #5
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    227

    Re: How to write to file (with the last write on the top)

    Quote Originally Posted by vineet.jain View Post
    Using RFile ::TInt Write(TInt aPos, const TDesC8 &aDes);, you can specify aPos to be 0. If that doesn't suits your requirement then RFile::Seek() may also be used & then write to file.
    I try RFile::Write(0, const TDesC8 &aDes), but the old log is replaced by the new log
    I want keep the old log too..
    How to do that?

    Thanks

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,173

    Re: How to write to file (with the last write on the top)

    If you are using Create(), then it will replace the old contents with new one, so try using Replace() (if you are not using it till now).

  7. #7
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    227

    Re: How to write to file (with the last write on the top)

    I'm already using Replace at constructL

    So what I'm doing is something like this
    Code:
    void CMyClass::ConstructL()
       {
       ...
       iFileLog.Replace(CEikonEnv::Static()->FsSession(), _L("C:\\data\\Log.txt"), EFileWrite | EFileShareAny);
       ...
       }
    void CMyClass::WriteLog(const TDesC8& aText)
       {
       iFileLog.Write(0, aText);
       }
    when I call function WriteLog twice... the log on first call replaced by the new log

  8. #8
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,004

    Re: How to write to file (with the last write on the top)

    Try utilizing the seek() then, like this:

    void CMyClass::WriteLog(const TDesC8& aText)
    {
    RFs fs;
    RFile file;
    User::LeaveIfError(fs.Connect());
    User::LeaveIfError(file.Open(fs, _L("C:\\data\\Log.txt"), EFileWrite));

    TInt pos = 0;
    file.Seek( ESeekStart, pos);
    file.Write( aDes);

    file.Close();
    fs.Close();
    }

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,683

    Re: How to write to file (with the last write on the top)

    RFile::Replace always ends up with a brand new empty file, replacing any possible existing one.
    There is no one-liner for keeping the old data, you need to combine Open and Create. If one of them fails, try the other. I found such code in #13 of http://www.developer.nokia.com/Commu...-this-function

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,683

    Re: How to write to file (with the last write on the top)

    Just noticed that you want to have the most recent line at the top.
    Something like
    Code:
    2011-12-27 Log File created
    then
    Code:
    2012-01-01 New Year
    2011-12-27 Log File created
    Text files do not support "insert" operation, so for this case the closest thing you can do is re-writing the entire file having the new line written first. Note that this approach costs a lot of memory and/or a lot of time and also causes significant wear to the flash memory of the devices.
    I do not suggest it in short. If you need the functionality for comfort reasons, it is a better choice to create a viewer application which can show you the log file in reverse order.

  11. #11
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    227

    Re: How to write to file (with the last write on the top)

    Thanks wizard_hu_, maybe I just ignore this try (yes, this functionality for comfort reason)
    And keep writing like usually... the last log in the bottom

    Thanks

Similar Threads

  1. RComm::Write() just write 8 bytes of data
    By ehsanTC in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2011-10-04, 20:00
  2. Write File
    By DavidCampos in forum Mobile Java General
    Replies: 5
    Last Post: 2009-08-24, 17:16
  3. very simple middlet class to write to write a text file
    By a_sina_a in forum Mobile Java General
    Replies: 10
    Last Post: 2008-03-07, 16:35
  4. RComm::Write()->Not able to write 259 bytes at a time
    By nokia_forum_chandru in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2007-08-06, 04:56
  5. Write to file....
    By VinodRaut in forum Symbian
    Replies: 9
    Last Post: 2007-05-24, 11:54

Posting Permissions

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