亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過在 java 中傳遞值將結果寫入 html 文件 - 任何幫助將不勝感激

通過在 java 中傳遞值將結果寫入 html 文件 - 任何幫助將不勝感激

POPMUISE 2022-12-28 09:47:21
放置的報告已經覆蓋了我想在帶有結果的表格中打印的所有結果但是當我打印它時覆蓋了結果并且它只打印一行正在從其他類文件傳遞值以打印結果我試過使用 Buffered writer 來編寫代碼public void createTestSummaryHTMLTable(String sample,String samp[le,String sample,String passedText,String status) throws IOException {    File file=new File("C:\\AutomationResults\\Forms\\",foldername);    if(!file.exists()){        file.mkdir();}      final String FILE_PATH =(file+"/"+formname);    //final String FILE_PATH = "C:\\AutomationResults\\Forms\\"+formname;    final String FILE_EXTENSION = "html";    DateFormat df = new SimpleDateFormat("yyyyMMdd"); // add S if you need milliseconds    String filename = FILE_PATH + "_"+ df.format(new Date()) + "." + FILE_EXTENSION;    File file2 = new File(filename);    // if file doesnt exists, then create it    if (!file2.exists()) {        file2.createNewFile();    }    BufferedWriter html = new BufferedWriter(new FileWriter(file2));    html.write("<html><body bgcolor='#E6E6FA'><table border=1 cellpadding=0>");    html.write("<title>Automation Summary report </title>");    html.write("<br>");    html.write("<center><strong><em>Batch report heading</em></strong>");    html.write("<span style ='float; right;position:relative;right:30px;font weight:bold'>"+new Date().toString()+"</span>");    html.write("<tr>");    addlabel1(html,"Test Step Name");    addlabel1(html,"Test Step Description");    addlabel1(html,"Status");       addlabel1(html,"Screenshot");    html.write("</tr>");    html.write("<tr>");    html.newLine();    addlabel(html,sample);    addlabel(html,sample);    String status1 = "Passed";    if (status1.equals(status))    {        html.write("<td width='20'style='color:#00F00;font-weight:bold;text-align:center'>"+status+"</td>");    } else {        html.write("<td width='20'style='color:#A52A2A;font-weight:bold;text-align:center'>"+status+"</td>");    }    addlabel(html,"Screenshot");    html.write("</tr>");    html.write("</table></body></html>");    html.close();}
查看完整描述

3 回答

?
慕雪6442864

TA貢獻1812條經驗 獲得超5個贊

您可以嘗試添加一個布爾參數,以FileWriter幫助指定它是應該附加到現有內容還是覆蓋現有內容。如果傳遞 true,它將以追加模式打開文件進行寫入。

請更改此行:

BufferedWriter html = new BufferedWriter(new FileWriter(file2));

對此:

BufferedWriter html = new BufferedWriter(new FileWriter(file2, true));


查看完整回答
反對 回復 2022-12-28
?
千巷貓影

TA貢獻1829條經驗 獲得超7個贊

實際結果

為每一行顯示標題我不需要為所有行顯示標題結果我得到的是預期結果

標題應該只顯示一次


查看完整回答
反對 回復 2022-12-28
?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

哦,我想我猜到了你的問題。寫入的文件是一個長行。

那是因為 write 只寫你給它的東西。您需要在所有字符串的末尾放置一個 \n。

或者,使用 Printwriter 的 println 方法輸出到您的文件。


查看完整回答
反對 回復 2022-12-28
  • 3 回答
  • 0 關注
  • 265 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號