更新時(shí)間:2022-09-21 10:20:28 來源:動(dòng)力節(jié)點(diǎn) 瀏覽3147次
Java生成html文件要怎樣做?代碼是什么?動(dòng)力節(jié)點(diǎn)小編來告訴大家。
在eclipse中,用java動(dòng)態(tài)生成html文件。
//用于存儲(chǔ)html字符串
StringBuilder stringHtml = new StringBuilder();
try{
//打開文件
PrintStream printStream = new PrintStream(new FileOutputStream("./Data/test.html"));
}catch(FileNotFoundException e){
e.printStackTrace();
}
//輸入HTML文件內(nèi)容
stringHtml.append("<html><head>");
stringHtml.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\">");
stringHtml.append("<title>測(cè)試報(bào)告文檔</title>");
stringHtml.append("</head>");
stringHtml.append("<body>");
stringHtml.append("<div>hello</div>");
stringHtml.append("</body></html>");
try{
//將HTML文件內(nèi)容寫入文件中
printStream.println(stringHtml.toString());
}catch (Exception e) {
e.printStackTrace();
}
注意:生成html文件的需要需要注意meta頭部的charset的配置。
相關(guān)閱讀
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)