public static void makeHtml() {
try {
URL url = new URL("http://www.baidu.com/");
//本实事例通过读取百度页面来生成静态页面,你要是想把自己程序里面要生成的jsp页面转化成静态页面,则可以在url构造器的参数中的参数写上:如http://localhost:8081/NEW/new.do?cmd=list&sortId=2
URLConnection conn = url.openConnection();//获得连接
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
BufferedWriter bw = new BufferedWriter(new FileWriter("D:/baidu.html"));
String str = null;
while ((str = br.readLine()) != null) {
bw.write(str);
}
bw.close();
br.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1337845