how to write in file with RFile

Login to reply to this topic.
Tue, 2006-04-04 00:50
Joined: 2006-04-03
Forum posts: 80
i am trying to write file with the following
code
the following code complies but my application gives a run time error.
please have some view.

code:

TBuf8<128> buffer;
file.Write(buffer);

Vasant Patel.
Sr. Software Engineer.
S60 2nd Ed., S60 3rd Ed., Win32.


Tue, 2006-04-04 01:08
Guest (not verified)
Forum posts: 2043
Re: how to write in file with RFile
You can't expect an answer to a question with such useless information as this!

What is file, an RFile presumbably but did you open it etc., what is the run time error, etc.?

Tue, 2006-04-04 04:54
Joined: 2005-09-01
Forum posts: 15
Re: how to write in file with RFile
include : f32file.h, eikenv.h
library: efsrv.lib

Code:
RFile file;
file.Replace( CEikonEnv::Static()->FsSession(), _L("c:\\test.txt"), EFileWrite );
file.Write( _L8("test") );
file.Close();

hope this helps

best regards,
Ronald Stevanus

Tue, 2006-04-04 07:15
Joined: 2005-07-25
Forum posts: 31
Re: how to write in file with RFile
Hi

First Let us know what you want towrite ?

Point 1. You want to write Textl Data into the file
Point 2. You want to write the binary data into the file?

Binary data (When you want copy some image audio or video data)

Because both has the diffrent mechanism to write in
the file.

Make your question clear

Regards
Ranjeet
Thu, 2006-04-06 12:14
Joined: 2005-03-30
Forum posts: 206
Re: how to write in file with RFile
hi,

first i asume that u use this piece of code in a GUI based application , because in an exe u won't be able to get a RFs like u did. Second check the return codes of every method that u used... if all is ok u should get KErrNone.

guda

Thu, 2006-04-06 18:20
Joined: 2006-04-03
Forum posts: 80
Re: how to write in file with RFile
sorry to all for my incomplete information

and thanks for taking interest

my code is as follows


RFs aFs;   
aFs.Connect();
RFile file;
   
TInt iErr = file.Open(aFs,KLTrackSettingsFile,EFileWrite);
   
if (iErr != KErrNotFound)
    {

TBuf8<128> FileContents;   
FileContents.Append(iInterval);
// iInterval is an TInt
FileContents.Append('\n');
FileContents.Append(iGetLocation);
// iGetLocation is a boolean
FileContents.Append('\n');
FileContents.Append(iCreateLog);
//createLog is a boolean
FileContents.Append('\n');
FileContents.Append(iTimerActive);
// itimer activer is also boolean
FileContents.Append('\n');
iErr =file.Write(FileContents);// i am getting runtime here



error is as follows
38c6f
KERN-EXEC 0


Vasant Patel.
Sr. Software Engineer.
S60 2nd Ed., S60 3rd Ed., Win32.

Fri, 2006-04-07 06:43
Joined: 2005-09-16
Forum posts: 141
Re: how to write in file with RFile
Hi,

for this, first u check file exists or not using Baflutils::FileExists().
if file exists, then open the file and write data.
else create the file for write and write the data

it'll help for u
Fri, 2006-04-07 06:47
Joined: 2004-01-09
Forum posts: 188
Re: how to write in file with RFile
Hi vasant,

iErr != KErrNotFound, this doesn't means that your file reference has created there might be other problems like already in use.

So better use it like this.

RFs aFs;  
aFs.Connect();
RFile file;
 
TInt iErr = file.Open(aFs,KLTrackSettingsFile,EFileWrite);
 
if (iErr == KErrNone)
   {

TBuf8<128> FileContents;  
FileContents.Append(iInterval);
// iInterval is an TInt
FileContents.Append('\n');
FileContents.Append(iGetLocation);
// iGetLocation is a boolean
FileContents.Append('\n');
FileContents.Append(iCreateLog);
//createLog is a boolean
FileContents.Append('\n');
FileContents.Append(iTimerActive);
// itimer activer is also boolean
FileContents.Append('\n');
iErr =file.Write(FileContents);
}
else
{
// Handle error
}

file.Close();
aFs.Close();


*********
BR
Chetan

----
Chetan Kulshrestha

Mon, 2006-04-10 19:12
Joined: 2006-04-03
Forum posts: 80
Re: how to write in file with RFile
hi all,

thanks very much  for your kind interest

my problem is solved
and the problem was that unknowingly
my file  was already opened and i was trying to reopen.


thanks.

Vasant Patel.
Sr. Software Engineer.
S60 2nd Ed., S60 3rd Ed., Win32.

  • Login to reply to this topic.