package test;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
/**
* 代码生成器
* @author penghuaiyi
* @date 2011-09-09
*/
public class CodeUtil {
public static void createHtml(){
OutputStream os = null;
OutputStreamWriter osw = null;
BufferedWriter bw = null;
try{
os = new FileOutputStream("c:\\temp\\test.html");
osw = new OutputStreamWriter(os,"UTF-8");
bw = new BufferedWriter(osw);
bw.write("<html>\r\n");
bw.write("<head>\r\n");
bw.write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n");
bw.write("<title>文本测试</title>\r\n");
createScript(bw);
bw.write("</head>\r\n");
bw.write("<body οnlοad=\"init()\">\r\n");
createTable(bw);
bw.write("</body>\r\n");
bw.write("</html>\r\n");
bw.flush();
}catch(Exception e){
e.printStackTrace();
}finally{
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void createScript(BufferedWriter bw) throws IOException{
bw.write("<script type=\"text/javascript\">\r\n");
bw.write("\tfunction init(){\r\n");
bw.write("\t\talert('初始化');\r\n");
bw.write("\t}\r\n");
bw.write("</script>\r\n");
}
public static void createTable(BufferedWriter bw) throws IOException{
bw.write("<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
bw.write("<tr>\r\n");
for(int j=0;j<5;j++){
bw.write("<td>列"+j+"</td>\r\n");
}
bw.write("</tr>\r\n");
for(int i=0;i<10;i++){
bw.write("<tr>\r\n");
for(int j=0;j<5;j++){
bw.write("<td>"+j+"</td>\r\n");
}
bw.write("</tr>\r\n");
}
bw.write("</table>\r\n");
}
public static void main(String[] args){
createHtml();
}
}