Copy Code code as follows:
Package com.tools;
Import java.io.*;
Import Java.net.URL;
/**
* Title: Dynamic page static
*/
public class Gotohtml {
/**
*
* @param page
* Local file path for static pages (C,D,E,F,G)
* @param url_addr
* URL address of the static page to be generated (http://)
* @return
*/
public boolean PrintPage (String page, string url_addr) {
System.out.println ("page" + page);
String newpage = "";
Determines whether the local path entered is in. The end of the JSP
if (Page.endswith (". html")) {
System.out.println ("This are end with xxx.html");
int bias = Page.lastindexof ("/");//bias (meaning of slash) gets the position of the last slash
System.out.println ("The last/at:" + bias);
NewPage = page.substring (0, bias);
System.out.println ("newpage:" + newpage);
}
If the folder does not exist, create a
File FF = new file (newpage);
Ff.mkdirs ();
URL url;
String rline = null;
PrintWriter fileout = null;
InputStream ins = null;
try {
url = new URL (url_addr);
System.out.println (url+ "...");
INS = Url.openstream ();
BufferedReader breader = new BufferedReader (New InputStreamReader (
INS, "Utf-8"))//Get files encoded as gb2312
FileOutputStream out = new FileOutputStream (page);
OutputStreamWriter writer = new OutputStreamWriter (out, "utf-8");
Fileout = new PrintWriter (writer);
Iterates through the data and writes to the destination file
while ((Rline = Breader.readline ())!= null) {
String tmp_rline = rline;
System.out.println (Tmp_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 {//shutdown resource
Fileout.close ();
try {
Ins.close ();
catch (IOException ex) {
Turn off input and outflow error
Ex.printstacktrace ();
}
}
}
public static void Main (string[] args) {
gotohtml gth = new gotohtml ();
String accresstoken= "w67k0vh4k5yph3dpk75jkmechvw_utybtqjd-vb8vxrfd3aovhhk_apjq7jmouhiytsru3_voj2ixrccluab_6- Hblsmxzz_dwqtup3908aoioukkrnxllagh0ac7rnvsazybyxwi8670us-ryd1va ";
String media= "y9kk2wmps4byzxiyfz7_nq6gyi8ev7-hyzg5hbadkoqoblfs9jit8_x2s4zovc1g";
String urlstring= "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" +accresstoken+ "&media_id=" + Media
Gth. PrintPage ("d:/eclipse/newnum.html", "http://localhost/prime/user/userFind_update.jsp?id=93");
Gth. PrintPage ("d:/newnum.html", urlstring);
}
}