/*** @Title: MakeHtml
* @Description: 创建html
*@paramfilePath 设定模板文件
*@paramconent 替换的内容
*@paramdisrPath 生成html的存放路径
*@paramfileName 生成html名字
*@returnvoid 返回类型
*@throws
*/
public static voidMakeHtml(String filePath,String conent,String disrPath,String fileName ){
InputStreamReader bis= null;try{
System.out.print(filePath);
String templateContent= "";
FileInputStream fileinputstream= new FileInputStream(filePath);//读取模板文件
StringBuffer sb = newStringBuffer();
bis= new InputStreamReader(fileinputstream,"UTF-8");
BufferedReader br= newBufferedReader(bis);int i=0;while((i=br.read())!=-1){
sb.append((char)i);
}
templateContent=sb.toString();
templateContent= templateContent.replaceAll("模板内容", conent);
String fileame= fileName + ".html";
fileame= disrPath+"/" + fileame;//生成的html文件保存路径。
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流
System.out.print("文件输出路径:");
System.out.print(fileame);/*byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();*/OutputStreamWriter osw= new OutputStreamWriter(fileoutputstream,"UTF-8");
BufferedWriter bw=newBufferedWriter(osw);/*int j=0;
while((j=br.read())!=-1){
bw.write(j);
}*/bw.write(templateContent);
bw.close();
}catch(Exception e) {
System.out.print(e.toString());
e.printStackTrace();
}finally{try{
bis.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}