Java Paging Read File method

Source: Internet
Author: User

Public static void readforpage (File sourcefile, int pageno,int pagesize)  throws ioexception {  filereader in = new filereader (SourceFile) ;   linenumberreader reader = new linenumberreader (in);   String s  =  "";  /*if  (linenumber <= 0 | |  linenumber > gettotallines (sourcefile))  {       System.out.println ("Not within the number of lines in the file (1 to total number of rows)." ");       system.exit (0);   }  */int startrow =   (pageno - 1)  * pagesize + 1;int endrow = pageno *  pagesize;int lines = 0;  system.out.println ("StartRow:" +startRow); System.out.println ("Endrow:" +endrow);while  (s != null)  {       lines++;     &nBsp;s = reader.readline ();       if (Lines >= startrow  && lines <= endrow)  {           system.out.println ("line:" +lines+ ":" +s);           //system.exit (0);       }  }  reader.close ();   in.close ();       }

This is called:

Public static void main (String[] args)  {           //  Specifies the line number to read           int  linenumber = 2;            //  reading files             //file sourcefile = new  file ("D:/java/test.txt");          file  Sourcefile = new file ("D://1.txt");                    try {            readforpage (sourcefile, 5, 8);         } catch  (ioexception e)  {               // todo&nBsp auto-generated catch block               e.printstacktrace ();          }                 }


Java Paging Read File method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.