importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importjava.net.HttpURLConnection;importjava.net.URL;public classMakeHtml {public static booleanJspToHtmlFile(String filePath, String saveHtmlFile) {
String str= "";
StringBuffer buffer= newStringBuffer();/*try {
String tempStr = "";
InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath), "UTF-8");
BufferedReader br = new BufferedReader(isr);
while ((tempStr = br.readLine()) != null){
str = str + tempStr +"\n";
}
} catch (IOException e) {
e.printStackTrace();
return false;
}*/
try{
URL url= newURL(filePath);
HttpURLConnection httpUrl=(HttpURLConnection)url.openConnection();
InputStream is=httpUrl.getInputStream();
BufferedReader br= new BufferedReader(new InputStreamReader(is,"utf-8"));
StringBuilder sb= newStringBuilder();
String line;while ((line = br.readLine()) != null) {
buffer.append(line+"\n");
}
is.close();
br.close();
}catch(Exception e) {
}try{
str= buffer.toString().replaceAll("###imageUrl###","http://img.zcool.cn/community/0142135541fe180000019ae9b8cf86.jpg@1280w_1l_2o_100sh.png");//必须设置编码格式不然会出现乱码
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveHtmlFile),"UTF-8"));
bufferedWriter.write(str);
bufferedWriter.newLine();//换行
bufferedWriter.flush();
bufferedWriter.close();
}catch(Exception e) {
e.printStackTrace();return false;
}return true;
}public static voidmain(String[] args) {long begin =System.currentTimeMillis();
String url= "http://xxx/banner/modelHtml.html";//模板文件地址
String savepath = "d:/" + begin + ".html";//生成文件地址
JspToHtmlFile(url, savepath);
System.out.println("用时:" + (System.currentTimeMillis() - begin) + "ms");
}
}