本文介绍了QFile:如何有效地仅读取从k到k + L的字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以从QFile读取从k到k + L的字节,将第一个完整文件读取到QByteArray
I can read bytes from k to k+L from QFile reading first whole file into QByteArray
if (!file.open(QIODevice::ReadOnly))
//...
QByteArray blob = file.readAll();
QByteArray bytes = blob.mid( k, L);
如何仅从k到k + L高效地读取字节?
How to read just bytes from k, to k+L, efficiently ?
if (!file.open(QIODevice::ReadOnly))
//...
QByteArray bytes = bytesFromFile( file, k, L);
推荐答案
使用seek方法获取您要开始读取的文件中的位置.然后从该点开始使用read方法读取所需的字节数.
Use the seek method to get to the position in the file you want to start reading.Then use the read method to read as many bytes as you want from that point.
即.
if (!file.open(QIODevice::ReadOnly)){
file.seek(k);
QByteArray bytes = file.read(L);
}
这篇关于QFile:如何有效地仅读取从k到k + L的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!