Generate static page Java code

Source: Internet
Author: User


Package Com.fang.news.test;import Java.io.bufferedreader;import Java.io.bufferedwriter;import Java.io.fileoutputstream;import Java.io.inputstream;import Java.io.inputstreamreader;import    Java.io.outputstreamwriter;import Java.net.httpurlconnection;import java.net.url;/** * * Project name: NewsPortalProject * Class Name: Htmlmaker * Class Description: * Creator: Xianjuanjuan * creation time: July 23, 2015 PM 5:34:02 * @version * */public class HTM   Lmaker {Final static object lock = new Object ();    public static void Makehtml (String page, String filePath) {makehtml (Page,filepath, "utf-8"); public static void Main (string[] args) {String page = "http://bj.58.com/"; String FilePath = "d://test.html"; makehtml (page, FilePath);} public static void Makehtml (String page, String filepath,string chartset) {synchronized (lock) {Httpurlconnecti     on huc = null;     BufferedReader br = null;     BufferedWriter bw = NULL;     try {Huc = (httpurlconnection) New URL (page). OpenConnection (); System.setpRoperty ("Sun.net.client.defaultConnectTimeout", "30000");      System.setproperty ("Sun.net.client.defaultReadTimeout", "30000");     Huc.connect ();     InputStream stream = Huc.getinputstream ();     BW = new BufferedWriter (new OutputStreamWriter (New FileOutputStream (FilePath), chartset));     br = new BufferedReader (new InputStreamReader (Stream, chartset));     String Line;     while (line = Br.readline ())! = null) {if (Line.trim (). Length () > 0) {bw.write (line);     Bw.newline ();     }}} catch (Exception e) {e.printstacktrace ();     } finally {try {br.close ();     Bw.close ();     Huc.disconnect ();     } catch (Exception e) {e.printstacktrace (); }     }      }    }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Generate static page Java code

Related Article

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.