你如何使用Symbian的RFile打开文件?

时间:2011-02-11 18:13:16

标签: c++ mobile symbian

我刚刚开始为Symbian开发。我目前正在使用诺基亚Qt。我正在尝试基于mime类型启动另一个应用程序。我目前正在关注此example。我想尝试打开.txt文件。

我发现很难理解如何创建RFile以及TDesC16类实际上是什么/做什么?

在示例中,基本上完成工作的代码如下:

// Gets the UID and MIME type for the given file name.
TUid uid;
TDataType dataType;
User::LeaveIfError(session.AppForDocument(aFileName, uid, dataType));

// Runs the default application using the MIME type, dataType.
// You can also use the UID to run the application. 
TThreadId threadId;
User::LeaveIfError(session.StartDocument(aFileName, dataType, threadId));

变量aFileName必须是RFile类型。那么我如何创建这个对象来打开存储在Computer \ Nokia C7-00 \ Phone memory \ test.txt(在资源管理器中)的.txt文件。

1 个答案:

答案 0 :(得分:1)

TDesC16是一个Symbian描述符,基本上是一个字符串。这是一本很好的手册:http://descriptors.blogspot.com/

至于你的问题。在示例中,它看起来像aFileName是一个描述符。 所以打开test.txt做这样的事情:

TThreadId threadId;
User::LeaveIfError(session.StartDocument(_L("c:\test.txt"), dataType, threadId));

如果您想使用RFile,请参阅以下代码示例:

RFs fs;
User::LeaveIfError(fs.Connect()); // connect to File Server
CleanupClosePushL(fs); // adding to the cleanup stack to ensure that the resources are released properly if a leave occurres while opening a file

RFile file;
User::LeaveIfError(file.Open(fs, _L("c:\test.txt"), EFileRead));
CleanupClosePushL(file);

// do something with file

CleanupStack::PopAndDestroy(2); // closes file and fs and removes them from the cleanup stack;