Symbian 读写 INI 配置文件的方法
2010-04-20 16:06:00 来源:WEB开发网//open file
RFile file;
TUint shareMode=EFileRead | EFileWrite ;
file.Open( fs, filename,shareMode ) ;
TInt fileSize=0;
file.Size(fileSize); //ȡ???ļ???С
CnvUtfConverter *cutf=new (ELeave) CnvUtfConverter;
HBufC8 *bufc = HBufC8::NewL(fileSize+1);
TPtr8 ptr8(bufc->Des());
file.Read(ptr8);
//LogToFile(_L(“c:\cbm\rsadebug.txt”), bufc->Des());//
TInt res;
TPtrC8 iCursor(bufc->Des());
TBuf<256> buf16;
//TBuf8<2> bufPage;
//bufPage.Format(_L8(“%02d”), res);
//LogToFile(_L(“c:\cbm\rsadebug.txt”), bufPage);
while( ( res = iCursor.FindF(KCRLF) ) >= 0 ) {
res = iCursor.FindF(KCRLF);
TPtrC8 result = iCursor.Left(res);
iCursor.Set(iCursor.Right(iCursor.Length() ? (res +2)));
buf16.Zero();
buf16=cutf->ConvertToUnicodeFromUtf8L(result)->Des();
lines.AppendL(buf16);
}
if(iCursor.Size()>0) {
buf16.Zero();
buf16=cutf->ConvertToUnicodeFromUtf8L(iCursor)->Des();
lines.AppendL(buf16);
}
delete cutf;
delete bufc;
file.Close();
}
fs.Close();
}
void CFile::GetLinesFromFile(const TDesC& filename,CDesC8Array& lines){
RFs fs;
User::LeaveIfError(fs.Connect() );
if( BaflUtils::FileExists(fs,filename) ){
//open file
RFile file;
TUint shareMode=EFileRead | EFileWrite ;
file.Open( fs, filename,shareMode ) ;
TInt fileSize=0;
file.Size(fileSize);
CnvUtfConverter *cutf=new (ELeave) CnvUtfConverter;
HBufC8 *bufc = HBufC8::NewL(fileSize+1);
TPtr8 ptr8(bufc->Des());
更多精彩
赞助商链接