How to read TXT file in batches?
<p>Now I am developing a reader. If the txt file is too big, it will spend a long time to read and no response. So I want to set a method like it can read the txt file in bathes.</p>

<p>I write the below code. It can turn the page back. But it can not page up continuous. How should I do?</p>

<pre><code> Vector string; 
 int begin = 0;

 public void readTxtByPage(String fileName) {
        string.clear();
        FileReader fr  = null;
        BufferedReader br = null;
        try {
            fr = new FileReader(filePath + fileName);
            br = new BufferedReader(fr);
            br.skip(begin);
            String content = "";
            char ch;
            int line = 0;
            int w;
            int len;
            int start;
            FontMetrics fm = paint.getFontMetrics();
            fontHeight = (int) Math.ceil(fm.descent - fm.top) + 2;
            pageLineNum = textHeight / fontHeight;
            float[] widths = new float[1];
            while ((content = br.readLine()) != null) {
                len = content.length();
                w = 0;
                start = 0;
                for (int i = 0; i &lt; len; i++) {
                    ch = content.charAt(i);
                    paint.getTextWidths(String.valueOf(ch), widths);
                    w += Math.ceil(widths[0]);
                    if (w &gt; textWidth) {
                        string.addElement(content.substring(start, i));
                        begin += (i - start);
                        start = i;
                        w = 0;
                        line++;
                        if (line &gt;= pageLineNum) {
                            System.out.println("begin===&gt;"+begin);
                            return;
                        }
                    }
                }
                string.addElement(content.substring(start));
                begin += (len + 2 - start);
                line++;
                if (line &gt;= pageLineNum) {
                    return;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                br.close();
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return;
    }
</code></pre>

<p>Thanks in advance!</p>
