Java reads HTML files, intercepts <body> tag contents

Source: Internet
Author: User

1      Publicstring ReadFile (String filePath) {2File File =NewFile (FilePath); 3InputStream input =NULL;4         Try {5input =Newfileinputstream (file);6}Catch(FileNotFoundException e) {7 e.printstacktrace ();8         }  9StringBuffer buffer =NewStringBuffer (); Ten         byte[] bytes =New byte[1024]; One         Try { A              for(intn; (n = input.read (bytes))!=-1 ; ) {   -Buffer.append (NewString (Bytes,0,n, "GBK"));  -             } the}Catch(IOException e) { - e.printstacktrace (); -         } - //System.out.println (buffer); +         returnbuffer.tostring ();  -     } +      A       Publicstring GetBody (string val) { atString start = "<body>"; -String end = "</body>"; -           ints = Val.indexof (start) +start.length (); -           intE =val.indexof (end); -         returnval.substring (S, e); -     } in     
1      Public Static voidmain (String [] args) {2Oadao m =NewOadao ();3 //String sql = "Select Sth,xdh from tk_st_0331 where sth= ' 022012050101131000100 ' and rownum <=10";4String sql = "Select T.sth, T.STGJZ, t.stly, x.mc from tk_st_0331 T, tk_stk_st_0331 k,tk_tx x where t.sth = K.sth and X. BH = T.tx and RowNum <10 ";5List<oavo> datalist=m.findall (SQL);6          for(Oavo vo:datalist) {7System.out.println (Vo.getval1 () + "//" +Vo.getval2 ());8             9 //String sth = "022012010100000100100";TenString STH =Vo.getval1 (); OneString kmh = sth.substring (0, 2);//Account Number AString NF = sth.substring (2, 6);//year -String YF = sth.substring (6,10);//Month -String Serialno = sth.substring (10, 16);//Serial Number theString STXL = sth.substring (16, 19);//Types -String path = "/" +kmh+ "/" +nf+ "/" +yf+ "/" +serialno+ "/" +stxl+ "/"; -              -String Tm_path = "h:/tk_source/" +kmh+ "/" +yf+ "/" +serialno+ "/" +stxl+ "/" +sth+ "_tm.htm"; +String Da_path = "h:/tk_source/" +kmh+ "/" +yf+ "/" +serialno+ "/" +stxl+ "/" +sth+ "_da.htm"; -String Jx_path = "h:/tk_source/" +kmh+ "/" +yf+ "/" +serialno+ "/" +stxl+ "/" +sth+ "_jx.htm"; +              A     //String Path = "h:/tk_source/02/0101/000001/001/022012010100000100100_da.htm"; at              -String TM =m.getbody (M.readfile (Tm_path)); -System.out.println ("----------------------topic------------------------------"); - System.out.println (tm); -              -String da =m.getbody (M.readfile (Da_path)); inSystem.out.println ("----------------------answer------------------------------"); - System.out.println (DA); to              +              -String JX =m.getbody (M.readfile (Da_path)); theSystem.out.println ("----------------------parsing------------------------------"); * System.out.println (JX); $         }Panax Notoginseng}

Java reads HTML files, intercepts <body> tag contents

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.