jmeter beanshell 读写文件
一、脚本结构
二、C盘创建city.txt 进行参数化操作,同时c盘创建c.txt 空文件进行数据写入操作
参数:msg ${city} b 默认写1
beanshell 脚本如下:
写入一列数据:
String line = vars.get("city");
log.info(line);
try{
BufferedWriter out = new BufferedWriter(new FileWriter("C:\\c.txt",true));
out.write(line);
out.newLine();
out.close();
} catch (IOException e){
e.printStackTrace();
}
beanshell 脚本如下:
写入两列数据:
String line = vars.get("city") + "," + vars.get("id");
log.info(line);
try{
BufferedWriter out = new BufferedWriter(new FileWriter("C:\\c.txt",true));
out.write(line);
out.newLine();
out.close();
} catch (IOException e){
e.printStackTrace();
}
参数: msg ${city} b ${id}
备注:beanshell 写入c.txt 1.数据随机追加写入 2.写入中文会有乱码