qt实现读写二进制文件
程序员文章站
2022-04-22 09:47:19
QFile file("D:\\Tcpview.exe");if (file.exists()){if ( file.size() > 2097152 ){QMessageBox::information(this, tr("up file fail"), tr("Failed to up file, file size need < 2M."));return;}if(!file.open(QIODevice::R.....
QFile file("D:\\Tcpview.exe");
if (file.exists())
{
if ( file.size() > 2097152 )
{
QMessageBox::information(this, tr("up file fail"),
tr("Failed to up file, file size need < 2M."));
return;
}
if(!file.open(QIODevice::ReadOnly))
{
QMessageBox::warning(this,tr("error"),tr("file no exit"),QMessageBox::Ok);
return;
}
else
{
////////////////////////////////////
//fstream fin;
ifstream fin("D:\\Tcpview.exe", ios::in | ios::binary);
//fin.open(filename2.c_str());
if(!fin)
{
cerr<<"open error!"<<endl;
return;
}
int i = file.size();
QByteArray str = file.read(i); //写
//注意:不可使用string str = file.read(i); //会被截断
QFile file2("D:\\Tcpview3.exe");
file2.open(QIODevice::WriteOnly);
file2.write(str.data(), i);
file2.close();
}
}
本文地址:https://blog.csdn.net/qq_33053671/article/details/107388240
上一篇: 装修选烤漆门和免漆门的区别,别再掉坑里了
下一篇: 文明的语言经典笑话