Inside a folder called Resources I have a text file called "hello.txt". How do I read it using blackberry 10 native sdk using cpp. I found something like using a FileConnection. But its showing FileConnection is not declared!!. Is there any header file required?? Please mind that I am using cpp:

FileConnection fc = (FileConnection) Connector.open("Resources/hello.txt", Connector.READ);

How do I do this?

有帮助吗?

解决方案

Use QFile and QTextStream classes to read or write from files.

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";
}

Here, readAll() would return whole content of the stream. You can use readLine() method if you want to read only few length of content.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top