if(file.open(QIODevice::WriteOnly)
file.write("hello Qt");
file.close();
以读的方式打开
if(file.open(QIODevice::ReadOnly))
{
QString str = file.readAll();
qDebug() << str;
}
当然也有其它两种方式来实现读/写文件
1.使用文本流读写文本文件
QFile file("myFile.txt);
if(file.open(QIODevice::WriteOnly))
{
QTextStream out(&file);
out << "Hello Qt" << 123;
}
if(file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
while(in.atEnd())
{
QString str;
str = in.readLine();
qDebug() << str;
}
}
2.使用数据流来读写二进制文件
QFile file("myFile.txt");
if(file.open(QIODevice::WriteOnly))
{
QD
file.write("hello Qt");
file.close();
以读的方式打开
if(file.open(QIODevice::ReadOnly))
{
QString str = file.readAll();
qDebug() << str;
}
当然也有其它两种方式来实现读/写文件
1.使用文本流读写文本文件
QFile file("myFile.txt);
if(file.open(QIODevice::WriteOnly))
{
QTextStream out(&file);
out << "Hello Qt" << 123;
}
if(file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
while(in.atEnd())
{
QString str;
str = in.readLine();
qDebug() << str;
}
}
2.使用数据流来读写二进制文件
QFile file("myFile.txt");
if(file.open(QIODevice::WriteOnly))
{
QD