QT文件操作

/*
写文件
*/

    QFile file(filePath);
    bool bo = file.open(QIODevice::WriteOnly | QIODevice::Append);
    //qDebug() << bo;
    QTextStream text_stream(&file);
    text_stream << byte;
    file.flush();
    file.close();


/*
遍历文件且删除或创建
*/

    QDir dir(strFeatures);
    if(dir.exists())
    {
        qDebug() << strFeatures << " has exist";
        QStringList files;
        QStringList nameFilters;
        nameFilters << "*.json";
        files = dir.entryList(nameFilters,QDir::Files|QDir::Readable,QDir::Name);
        for(auto file : files)
        {
            dir.remove(file);
        }
    }else
    {
        qWarning() << strFeatures << " not exist";
        dir.mkdir(strFeatures);
    }

 

posted @ 2019-01-29 10:42  徐沛东  阅读(312)  评论(0编辑  收藏  举报