Instance HTML file
<Html><Head><title>## #title # # #</Title><Metahttp-equiv="Content-type"Content="Text/html; CHARSET=GBK "></Head><Body><TableWidth="500"Border="0"align="Center"cellpadding="0"cellspacing="2" ><Tr><Tdalign="Center" >## #title # # #</Td></tr> <tr> <td Align= "center" >## #author # # </td> </tr> <tr> < td>## #content ###</td> </ tr><tr><td>### Html###</td></tr> </table></body></ HTML>
Java code:
Package com.util;
Import Java.io.BufferedReader;
Import Java.io.BufferedWriter;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.io.OutputStreamWriter;
Import Java.text.SimpleDateFormat;
Import Com.entity.Template;
/**
* Generate HTML
*/
public class Makehtml {
/**
* Generate static pages based on local templates
* @param jspfile JSP Road Warp
* @param htmlfile HTML Road Warp
* @return
*/
public static Boolean jsptohtmlfile (Template t,string filePath, String htmlfile) {
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd");
String str = "";
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";
}
System.out.println (str);
} catch (IOException e) {
E.printstacktrace ();
return false;
}
try {
str = Str.replaceall ("# # #softwareName # # #", T.getsoftwarename ());
Str=str.replaceall ("# # #downloads # #", T.getdownloads ());
str = Str.replaceall ("# # #icon # # #", T.geticon ());
str = Str.replaceall ("# # #type # # #", T.gettype ());
str = Str.replaceall ("# # #size # # #", T.getsize ());
str = Str.replaceall ("# # #version # # #", T.getversion ());
Str=str.replaceall ("# # #updateTime # #", Format.format (T.getupdatetime ()));
str = Str.replaceall ("# # #qrcode # # #", T.getqrcode ());
str = Str.replaceall ("# # #filepath # # #", T.getfilepath ());
str = Str.replaceall ("# # #introduce # # #", T.getintroduce ());
str = Str.replaceall ("# # #screenshot # # #", T.getscreenshot ());
str = Str.replaceall ("# # #feature # #", T.getfeature ());//replace the corresponding place in the module
Encoding format must be set or garbled
BufferedWriter bufferedwriter = new BufferedWriter (new OutputStreamWriter (New FileOutputStream (HtmlFile), "UTF-8"));
Bufferedwriter.write (str);
Bufferedwriter.newline ();//Line break
/* Refreshes the buffer of the stream.
* Key line of code. If this line of code is not added. The data is only persisted in the buffer. Not written into the file.
* Add this line to write the data to the destination. * */
Bufferedwriter.flush ();
Bufferedwriter.close ();
} catch (IOException e) {
E.printstacktrace ();
return false;
}
return true;
}
}
Reference: http://www.newxing.com/Tech/Java/Web/107.html
http://blog.csdn.net/maxracer/article/details/5436580
Http://www.itzk.com/thread-581970-52-1.shtml
http://blog.csdn.net/qingchenyuji/article/details/8236322
Java generates HTML files