×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    144

    Question RFile Read Problem

    Hi All,

    1. I want to read given number of bytes form file.
    2. I wnat number of bytes actually read.

    my code is

    Code:
          TBuf8 <50> szDataRead;
    	
    	TBuf <MAX_PATH> szFilePath;
    	_LIT(KFILE, "C:\\a.txt");
    	
    	szFilePath.Copy(KFILE);
    	
    	//
    	//	Connect file session.
    	//	
    	User::LeaveIfError(fsSession.Connect());
    	
    	//
    	//	Constructs & pushes object onto cleanup stack.
    	//
    	CleanupClosePushL(fsSession);	
    	
    	//
    	//	Open file.
    	//
    	iRetVal = rfile.Open(fsSession, szFilePath, EFileRead);
    	if (KErrNone != iRetVal)
    	{
    		CleanupStack::PopAndDestroy(1); // fsSession
    		
    		return;
    	}
    	
    	
    	CleanupClosePushL(rfile);
    	TInt iRead = 10;
    	iRetVal = rfile.Read(szDataRead, iRead);
    	if (KErrNone != iRetVal )
    	{
    		CleanupStack::PopAndDestroy(2);	//	rFileScanchk, fsSession
    		return;	
    	}

    if file a.txt is empty, still Read returns KErrNone and iRead contains value 10. so is it neccessary to check file size before any file operation? Read call not take care for this?how to get number of bytes actually read from file?


    Thanks & Regards,
    sheetal.

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

    Re: RFile Read Problem

    have you seen this function in sdk:

    TInt Read(TInt aPos, TDes8 &aDes, TInt aLength) const;

    it reads, from a particular position, in a desciptor you define, and the length to read,in your case its 10

  3. #3
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    213

    Re: RFile Read Problem

    Hi,
    Put:
    iRetVal = rfile.Read(szDataRead);
    Then check: szDataRead.Length() is the number of bytes you need.

    Regards
    Assayag

  4. #4
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    144

    Re: RFile Read Problem

    Quote Originally Posted by assayag View Post
    Hi,
    Put:
    iRetVal = rfile.Read(szDataRead);
    Then check: szDataRead.Length() is the number of bytes you need.

    Regards
    Assayag
    thanks.. i get it..

Similar Threads

  1. STLPort namespace issue
    By yickhong in forum Open C/C++
    Replies: 0
    Last Post: 2009-04-09, 08:54
  2. File read problem
    By kannabiran.krish in forum Symbian
    Replies: 1
    Last Post: 2007-09-14, 14:38
  3. Problem MMC+USB Connection
    By Fede81 in forum Symbian
    Replies: 1
    Last Post: 2007-06-14, 06:13
  4. Problem MMC+USB Connection
    By Fede81 in forum General Development Questions
    Replies: 3
    Last Post: 2006-07-19, 15:21
  5. Read Chinese Text file and Display Chinese on Canvas Problem?
    By goeast in forum Mobile Java General
    Replies: 4
    Last Post: 2002-09-18, 03:28

Posting Permissions

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