Java generates HTML files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.