阅读 225

Jmeter的beanshell中,向txt写入字符串数据的几种方式。

1.字符流

 

 

//指定输出文件所在的目录和名字,
String filename = "D://test.txt";//此处可以用txt,也可以用csv
//true为追加写入内容,如果每次都清空重写,将true删掉
FileWriter writer = new FileWriter(filename,true);
String data_name1 = vars.get("name1");//name1是我本地正则表达式提取出来的变量
String data_name2 = vars.get("name2");
writer.write(data_name1+","+data_name2);//多条数据用逗号分割
writer.write("\r\n");//换行操作,用于下一组数据换行展示
writer.close();

 

2.字节流

 

String filename = "F://review.txt";
File file = new File(filename);
FileOutputStream fs = new FileOutputStream(file,true);
fs.write("asdada".getBytes());
fs.write("\r\n".getBytes());
fs.close();

3.封装成类

 

 

 

public class JmeterReadAndWrite {
public static void writeTxt(String txtPath, String content){
File file = new File(txtPath);
FileOutputStream fs = new FileOutputStream(file,true);
fs.write(content.getBytes());
fs.write("\r\n".getBytes());
// fs.flush();
fs.close();
}

}
String str = vars.get("review_id");//正确的写法
String txtPath = "F:\\review.txt";
JmeterReadAndWrite.writeTxt(txtPath,str);
原文链接:https://blog.csdn.net/qq_34365469/article/details/101419994

原文:https://www.cnblogs.com/csiwei-229958907/p/15010894.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐