File is create with RFile.Write() function, it's content is plain text. I want to read this file line by line, just like a "StreamReader.ReadLine()" funtion in C#. But RFile class does not offers such function....
File is create with RFile.Write() function, it's content is plain text. I want to read this file line by line, just like a "StreamReader.ReadLine()" funtion in C#. But RFile class does not offers such function....
Hope this will helps you!
_LIT(KFileSpec,"C:\\Test.txt");
RFs fs;
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
RFile ifile;
TInt iErr1=file.Open(fs,KFileSpec,EFileRead);
if(iErr1==KErrNone)
{
TInt iSize;
file.Size(iSize);
HBufC8* buffer = HBufC8::NewLC(iSize);
TPtr8 ptr= buffer->Des();
file.Read(ptr);
file.Close();
CleanupStack::PopAndDestroy(buffer);
}
fs.Close();
CleanupStack::PopAndDestroy(&fs);
And if u want read through TFileText class then chk this link..
http://wiki.forum.nokia.com/index.ph...ead_a_CSV_file
Last edited by Tatavarthi; 2008-03-25 at 06:22. Reason: now go through it!
Look for TFileText in SDKs docs. Mind you that the line length is restricted to 256 characters.
-- Lucian
Thanks! I try it and it really wotk.
Another question, I write some CHINESE string to file using TFileText.Write(), And then I TFileText.Read() this string and display using iEikonEnv->InfoMsg(), the CHINESE string can display correctlly. But when I open the file in Windows Explorder using notepad, I can't read it's contents at all!
im trying to open file but it is not working, there is some unhandled exception in the TRAPD, here is my code please tell me whats the problem with it:
void CompressImage::Compress( const TDesC& aFilePath )
{
TInt FileSize;
RFs ServerObj;
ServerObj.Connect();
TRAPD(error, iFile.Open( ServerObj, aFilePath, EFileRead) );
if(error!=KErrNone)
{
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
TBuf<100> msg;
msg.AppendNum(error);
informationNote->ExecuteLD(msg);
}
iFile.Size( FileSize );
HBufC8* newbuff;
HBufC8* buff = NULL;
buff = HBufC8::NewL( FileSize );
TBuf8<256> t1;
TBuf8<256> t2;
iFile.Read( t1 );
CExifModify* ExifObj = CExifModify::NewL( t1 );
ExifObj->SetXResolutionL( 10, 10 );
ExifObj->SetYResolutionL( 20, 20 );
newbuff = ExifObj->WriteDataL( t2 );
iFile.Create( ServerObj, _L("c:\\Data\\Images\\BlueFlower.bmp"), EFileWrite );
iFile.Write( *newbuff );
iFile.Close();
iReader->NewL();
iReader->PrepareImageL( aFilePath );
iReader->Bitmap();
iCompressed = ETrue;
};
First of all, RFile::Open is not "OpenL", thus TRAP/D does not do anything to it. TryCode:TInt error=iFile.Open(...);
i have tried;
TInt error = iFile.Open( ServerObj, aFilePath, EFileRead);
here is my code:
TInt FileSize;
RFs ServerObj;
ServerObj.Connect();
TBuf<100> msg;
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD( aFilePath );
TInt error = iFile.Open( ServerObj, aFilePath, EFileRead);
msg.Num(error);
informationNote->ExecuteLD(msg);
......................................................
But is still it is not working, neither the error value is getting displayed.
If you want to have the error code displayed, useCode:User::LeaveIfError(iFile.Open( ServerObj, aFilePath, EFileRead));
Thank you for being so helpful! now im trying to change the resolution of .jpg file, everything is working fine but the application gets closed at this line"CExifModify* ExifObj = CExifModify::NewL( t1 );" , here is my code;
TInt FileSize;
RFs ServerObj;
ServerObj.Connect();
RFile zf1;
zf1.Open( ServerObj, aFileName, EFileRead);
zf1.Size( FileSize );
HBufC8* newbuff;
HBufC8* buff = NULL;
buff = HBufC8::NewL( FileSize );
TBuf8<7567> t1;
zf1.Read( t1 );
/* here */
CExifModify* ExifObj = CExifModify::NewL( t1 );
ExifObj->SetXResolutionL( 10, 10 ); ExifObj->SetYResolutionL( 20, 20 );
newbuff = ExifObj->WriteDataL( t1 );
zf1.Close();
zf1.Create( ServerObj, _L("c:\\Data\\Images\\myfile.jpg"), EFileWrite ); //Replacing the file
zf1.Write( *newbuff );
zf1.Close();
ServerObj.Close();
thanks again!!!
Have you enabled extended panic codes? http://wiki.forum.nokia.com/index.ph...ded_panic_code