×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Sep 2006
    Posts
    101

    Unhappy reading from a file and writing to another file

    hy! is anyone who can just help me reading from a binary file and writing it at another location.i.e. into another file....the loop here is not breaking at all........any solution....??????

    Code:
    RFs fsSession; 
    	RFile file,fileTemp; 
    	TFileText txt_file; 
    	User::LeaveIfError(fsSession.Connect());
    	TInt err=file.Open(fsSession,fileName,EFileRead|EFileShareReadersOnly); 
    	_LIT(fileTempName,"c:\\Data\\Documents\\temp.xyz");
    	err=fileTemp.Create(fsSession,fileTempName,EFileWrite); 
    	TBuf8<512> readBuf1;
    	//TDesC8 readBuf1 = new TDesC8();
    	//file.Read(readBuf1);
    	while(KErrEof != file.Read(readBuf1)){
    		TInt err=fileTemp.Write(readBuf1);
    		if(err!=KErrNone){
    			_LIT(errtxt,"Error Occurred While Writing");
    			informationNote->ExecuteLD(errtxt);
    			break;
    		}
    		else{
    			fileTemp.Flush();
    		}
    	}
    	fileTemp.Close();
    	file.Close();
    	fsSession.Close();

  2. #2
    Registered User
    Join Date
    Feb 2007
    Location
    India
    Posts
    1,128

    Re: reading from a file and writing to another file

    Hi, I think there are no problem but only u can check file size it may be more than 512 char, so plz first u check file size.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: reading from a file and writing to another file

    Hi,

    I think you'll understand the problem with your code if you read this in the SDK documentation for the RFile::Read() method you are using:

    Note that when an attempt is made to read beyond the end of the file, no error is returned. The descriptor's length is set to the number of bytes read into it. Therefore, when reading through a file,the end of file has been reached when the descriptor length, as returned by TDesC8::Length(), is zero.
    Hope that helps,
    Sorcery

  4. #4
    Regular Contributor
    Join Date
    Sep 2006
    Posts
    101

    Thumbs up Re: reading from a file and writing to another file

    yes i got it, it always returns KErrNone, so hve to chk for the length of desc copied..thanks

Similar Threads

  1. Reading and writing to file
    By rkuppala in forum Symbian
    Replies: 6
    Last Post: 2008-03-13, 09:59
  2. File reading & writing help, wav file redaing help
    By shubhamlahoti in forum Mobile Java General
    Replies: 6
    Last Post: 2007-06-27, 09:07
  3. Reading and Writing to file
    By rkuppala in forum Symbian
    Replies: 1
    Last Post: 2004-08-03, 15:17

Posting Permissions

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