JMeter-BeanShell寫數據到CSV文件


時間戳的命名方式避免出現導出記錄重復而無法再次導出的現象

 

 

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");//設置日期格式
String date = df.format(new Date());// new Date()為獲取當前系統時間,也可使用當前時間戳
/**
log.info(date);
vars.put("date1",date);
*/
byte[] result = prev.getResponseData(); //這個是獲取到請求返回的數據,prev是獲取上個請求的返回


String file_name = "D:\\apache-jmeter-3.2\\"+date+".xls";
//代表存放文件的位置和文件名,文件名最后帶上時間戳或者其他變量,不然循環執行該接口,會失敗
File file = new File(file_name);
FileOutputStream out = new FileOutputStream(file);
out.write(result);
out.close();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM