File read and write problem!!

Login to reply to this topic.
Tue, 2006-11-07 06:49
Joined: 2006-06-03
Forum posts: 26
Hi all,

I want to store a single flag value in a file so that each time program will refer that value and go ahead.

I have referred some threads in this as well as other forums. but cannot get the full idea.

Kindly help me to solve, how to write the value in file and read it from file??

Best regards

Tue, 2006-11-07 07:26
Joined: 2006-06-03
Forum posts: 26
Re: File read and write problem!!
I able to write text into file by using this code
Quote
_LIT(KFileName, "c:\\test.txt");
_LIT8(KData, "A1=12345&");

//...

RFs fs;
fs.Connect();
CleanupClosePushL(fs);

RFile file;
TInt err = file.Open(fs, KFileName, EFileShareAny | EFileWrite);
if(err != KErrNone)
{
   err = file.Create(fs, KFileName, EFileShareAny | EFileWrite);
}
if (!err)
{
   CleanupClosePushL(file);
   
   User::LeaveIfError(file.Write(KData));
   
   CleanupStack::PopAndDestroy(); // file
}
CleanupStack::PopAndDestroy(); // fs

but that comes in winscw\c path. (as I use 7.0 and 2nd sdk) I also did armi build but no such file is created in another folder.

So what should be done to create file in real device. I mean what should be the path for that. (currently my path is _LIT(KFileName, "c:\\test.txt"); )

Regards
Tue, 2006-11-07 07:36
Joined: 2005-11-16
Forum posts: 62
Re: File read and write problem!!
Hi,
you can create a directory using

Quote
fs.MkDir(_L("\\system\\apps\\your appname\\"));

and your file path should be
Quote
_LIT(KFileName, "\\system\\apps\\your appname\\test.txt");

hope this help you
rgrds
Badshah
Tue, 2006-11-07 12:11
Joined: 2006-06-03
Forum posts: 26
Re: File read and write problem!!
Thanx for reply!!

but I got the solution for that. The path is same for emulator and real device!

I have another problem of reading file Sad
I tried this
 TDes8 *aDes;
 file.Read(*aDes);
but not successfull yet!

I want to store the string of file in one variable. How can I achiece this??

Kindly help

Best regards
Tue, 2006-11-07 12:49
Joined: 2005-11-16
Forum posts: 62
Re: File read and write problem!!
Hi..
dont use the TDes8 as it is..
you can use a TBuf8 instead.
try this
Code:
TBuf8<50>aDes;
file.Read(aDes);

if your file contains some large amount of data,you can use a HBufC8 object instead of Tbuf8.
regards
Badshah
Tue, 2006-11-07 13:02
Joined: 2006-06-03
Forum posts: 26
Re: File read and write problem!!
Ohk....

Thanx..I got it!

Regards
  • Login to reply to this topic.