PDA

View Full Version : Read from File :: Help required



abghosh
27th February 2010, 12:59
Hi

I have file containing 1 GB of data. But I have to read only the last 1000 data from the file.
How can I go for it? Reading the entire file takes more than 15 minutes.

Thanks for any help.

Lesiok
27th February 2010, 13:02
Read about QFile::seek (http://doc.trolltech.com/4.6/qfile.html#seek) and QFile::size (http://doc.trolltech.com/4.6/qfile.html#size)

abghosh
27th February 2010, 13:06
Read about QFile::seek (http://doc.trolltech.com/4.6/qfile.html#seek) and QFile::size (http://doc.trolltech.com/4.6/qfile.html#size)

Hi Lesiok
Thanks for your help. But for using these functions I have to first know the number of lines in the file.
How can I get the number of lines in the file in one command?

JohannesMunk
27th February 2010, 13:32
Lines? 1 GB TextFile??

Otherwise QFile::size is really all you need.

If by lines you mean records of a given size, you can seek to QFile::size() - recordsize*1000 ...

Johannes

Lesiok
27th February 2010, 17:27
If lines have non const length the problem is not trivial.

abghosh
1st March 2010, 04:12
If lines have non const length the problem is not trivial.

Line sizes varies. Otherwise it would have been simple to multiply number of lines by each line size & subtract it from total file size.

In such case how can I do it?

Lesiok
1st March 2010, 07:09
Only reading all file. I think that it is time to change a philosophy. 1 GB text file it is not good idea.