Static Java for dynamic pages

Source: Internet
Author: User

Import java. Io .*;
Import java.net. url;

/**
* Title: static dynamic page
*/
Public class statichtmlfile {
/**
*
* @ Param page
* Local file path for storing static pages
* @ Param url_addr
* URL of the static page to be generated
* @ Return
*/
Public static Boolean printpage (string page, string url_addr ){
URL;
String rline = NULL;
Printwriter fileout = NULL;
Inputstream ins = NULL;
Try {
Url = new URL (url_addr );
INS = URL. openstream ();
Bufferedreader breader = new bufferedreader (New inputstreamreader (
INS, "gb2312"); // get the file encoded as gb2312
Fileoutputstream out = new fileoutputstream (PAGE );
Outputstreamwriter writer = new outputstreamwriter (Out, "gb2312 ");
Fileout = new printwriter (writer );
// Fetch data cyclically and write it to the target file
While (rline = breader. Readline ())! = NULL ){
String tmp_rline = rline;
Int str_len = tmp_rline.length ();
If (str_len> 0 ){
Fileout. println (tmp_rline );
Fileout. Flush ();
}
Tmp_rline = NULL;
}
Url = NULL;
Return true;
} Catch (ioexception e ){
System. Out. println ("error:" + E. getmessage ());
E. printstacktrace ();
Return false;
} Catch (exception ES ){
System. Out. println (ES. getmessage ());
Return false;
} Finally {// close the resource
Fileout. Close ();
Try {
INS. Close ();
} Catch (ioexception ex ){
// An error occurred while disabling the input stream.
Ex. printstacktrace ();
}
}

}

Public static void main (string [] ARGs ){
Printpage ("C:/sina.html", "http://www.sina.com /");
}
}

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.