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.