问题是,我必须读取文件并将其数据写入另一个文件。但是大小可能太大(大于8 gb)所以我按块(1 mb)读取文件,但我认为可以计算出块的最佳大小,那么我该怎么做呢?我应该使用什么工具?这是代码
const int BLOCK_SIZE = 1000000;
if(!(fin.open(QIODevice::ReadOnly)) == false &&
!(fout.open(QIODevice::WriteOnly)) == false) {\
long long m_file_size = fin.size();
QDataStream in(&fin);
QByteArray arrayOfBytes;
int counting = 0;
int check = 0;
long int bytesPerSecond = 0;
timer.start();
for(size_t i = 0; i <= m_file_size / BLOCK_SIZE; ++i) {
arrayOfBytes = fin.read(BLOCK_SIZE);
fout.write(arrayOfBytes);
bytesPerSecond +=BLOCK_SIZE;
if ((100 * ((timer.elapsed() + 50) / 100)) > 999 && (100 * ((timer.elapsed() + 50) / 100)) % 1000 == 0 && check != (100 * ((timer.elapsed() + 50) / 100)))
{
counting++;
check = (100 * ((timer.elapsed() + 50) / 100));//(10 * ((timer.elapsed() + 5) / 10));
bytesPerSecond = 0;
}
}
fin.close();
fout.close();
}
else{
qDebug()<<"Failed to open";
}
}