如何使用本机SDK访问黑莓10上的文本文件

Geo*_*aul 1 filesystems qt4 qfile blackberry-10

在名为Resources的文件夹中,我有一个名为"hello.txt"的文本文件.如何使用cpp使用blackberry 10 native sdk阅读它.我找到了类似于使用FileConnection的东西.但它的显示FileConnection没有声明!! 是否需要头文件?请注意我正在使用cpp:

FileConnection fc = (FileConnection) Connector.open("Resources/hello.txt", Connector.READ);
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

Nis*_*hah 7

使用QFile和QTextStream类从文件读取或写入.

QFile file("app/native/assets/text.txt");
if (file.exists()) {
    if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream textStream(&file);
        QString text = textStream.readAll();
        file.close();
    }
} else {
    qDebug() << "File doesn't exist";
}
Run Code Online (Sandbox Code Playgroud)

这里,readAll()将返回流的全部内容.如果只想读取少量内容,可以使用readLine()方法.