| 1234567891011121314151617181920212223242526272829303132333435 |
- #include "vutils.h"
- #include <QFile>
- #include <QDebug>
- VUtils::VUtils()
- {
- }
- QString VUtils::readFileFromDisk(const QString &filePath)
- {
- QFile file(filePath);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qWarning() << "error: fail to read file" << filePath;
- return QString();
- }
- QString fileText(file.readAll());
- file.close();
- qDebug() << "read file content:" << filePath;
- return fileText;
- }
- bool VUtils::writeFileToDisk(const QString &filePath, const QString &text)
- {
- QFile file(filePath);
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- qWarning() << "error: fail to open file" << filePath << "to write to";
- return false;
- }
- QTextStream stream(&file);
- stream << text;
- file.close();
- qDebug() << "write file content:" << filePath;
- return true;
- }
|