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 /");
}
}