#include <QCoreApplication> #include <QFileInfo> #include <QDebug> #include <QFile> #include <QIODevice> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QFile file("D:/qt/myqfileinfo/in.txt"); qDebug()<<file.exists(); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) qDebug()<<"open failed"; else{ while (!file.atEnd()) { QByteArray line = file.readLine(); qDebug()<<line; } } file.close(); //关闭文件 return a.exec(); }