×
Namespaces

Variants
Actions

How to read a CSV file using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

This article shows how to read a Comma Separated Values (CSV) file and save it into a database using Symbian C++.

Article Metadata
Article
Created: rathodavinash (28 Jun 2007)
Last edited: hamishwillee (27 Sep 2012)

The CSV File

Demo CSV file Below is a Demo CSV file whose contents will be read and a database will be populated.

avi,E:\Others\avi.amr
joe,E:\Others\joe.amr
jill,E:\Others\jill.amr
microsoft hotmail,E:\Others\msn.amr
google gmail,E:\Others\gmail.amr
yahoo yahoomail,E:\Others\ymail.amr
Winamp MP3,E:\Others\winamp.mp3
MySong MP3,E:\Others\mysong.mp3

The file is edited in notepad and saved with the Unicode formatting.

Code to read the file

The following function reads the above file and populates the database

iSearchDb = CBookstoreDb::NewL();
 
if(!BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), iDatabaseFile))
{
iSearchDb->CreateDbL(iDatabaseFile);
 
///////////////////Read CSV File
RFs fs;
fs.Connect();
RFile hist;
TBuf<300> iLine;
if (hist.Open(fs,KCSVFile,EFileRead) == KErrNone)
{
TFileText text;
text.Set(hist);
iLine.Copy( _L(" "));
while (iLine.Length() > 0)
{
text.Read(iLine);
iLine.ZeroTerminate();
if (iLine.Length() > 0)
{
TInt i = iLine.Locate(',');
TBuf<50> iTempDes;
TBuf<128> iTempPath;
 
iTempDes.Copy(iLine.Left(i));
iTempPath.Copy(iLine.Mid(i+1));
 
iSearchDb->AddWithSqlL(iTempPath,iTempDes);
}
}
hist.Close();
}
fs.Close();
// Read CSV File Done
}
This page was last modified on 27 September 2012, at 07:57.
69 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×