×
Namespaces

Variants
Actions

Read data from File - Dynamically

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: kiran10182 (04 May 2007)
Last edited: hamishwillee (25 Jul 2012)

Following code snippet illustrates reading data from file when the size of file in not known.

	_LIT(KFileSpec,"C:\\Test.txt");
RFs fs;
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
 
RFile file;
TInt Err1=file.Open(fs,KFileSpec,EFileRead);
if(Err1==KErrNone)
{
TInt Size;
file.Size(Size);
HBufC8* buffer = HBufC8::NewLC(Size);
TPtr8 ptr= buffer->Des();
file.Read(ptr);
file.Close();
CleanupStack::PopAndDestroy(buffer);
}
fs.Close();
CleanupStack::PopAndDestroy(&fs); // destroy fs

Note: Include f32file.h and link against efsrv.lib

This page was last modified on 25 July 2012, at 06:26.
37 page views in the last 30 days.
×