I need to implement a paging widget that would be able to read an arbitrarily large text file. widget will be used by different apps with a wide range of hardware (mobile with low ram on low end) so need to be fairly memory stingy and efficient. the amount to be paged is also going to be arbitrarily different for each user. is there any free sample code that has implemented this somewhere? i'm looking for a java snippet really if possible.
A:
You basically need to remember the amount of lines you already have read and then skip the same amount of lines in the while ((line = bufferedReader.readLine()) != null)
statement.
BalusC
2009-12-12 20:20:19
I guess the reading through the file is pretty obvious but my bigger concern is the management of the current/next page and the user experience as they scroll through the app.
2009-12-12 21:15:34
For quicker response, consider an embedded database. E.g. JavaDB, Derby or HSQLDB.
BalusC
2009-12-12 21:52:52
This loop might take a while for arbitrarily large files ...
meriton
2009-12-12 22:08:25
Is there a paging or pagination pattern that would encompass the reading of the data and managing the concept of previous and next page? It seems like both the RandomAcessFile() and the BufferedReader() solution maybe fairly simple to code. I guess the challenge I am facing is the management of the "pages" and ensuring decent performance.Thanks for the responses so far.
2009-12-15 18:06:03
RandomAccessFile is in theory faster, but it's also more work because you need to encode the characters yourself and find the linebreaks yourself. Maybe a combination of both should be doable.
BalusC
2009-12-15 18:30:35
+2
A:
java.io.RandomAccessFile should be helpful here, as it allows you start reading anywhere in the file. This enables you to only keep the current page in memory.
meriton
2009-12-12 22:07:19