如下图: 加入Cookie值
BeanShell代码如下:
import java.io.*;
import java.util.Random;
String filePath=vars.get("Path");
String fileName=vars.get("Name");
System.out.println(filePath+" This is origin file path!");
System.out.println(fileName+" This is origin file name!");
try {
File file = new File(filePath+"\\temp");
//判断文件不为null或文件目录存在
if (!file.exists()){
file.mkdir();//创建文件夹
}else if(file.list().length==0){
System.out.println("文件夹为空,无需初始化删除");
}else{
//取得这个目录下的所有子文件对象
File[] files = file.listFiles();
//遍历该目录下的文件对象
for (File f: files){
f.delete();
}
}
Random ra =new Random();
int num=ra.nextInt(10000)+1;
long r1 = System.currentTimeMillis();
//File csvFile = new File("D:\\Work\\TestData\\Excel\\testData_2_sensitive.xlsx"); // CSV数据文件
String csvFile = filePath+"\\"+fileName;
BufferedReader br = new BufferedReader(new FileReader(csvFile)); // 附加
String newFileName = filePath+"\\temp\\"+fileName.split("\\.")[0]+(ra.nextInt(10000)+1)+"."+fileName.split("\\.")[1];
BufferedWriter bw = new BufferedWriter(new FileWriter(newFileName, true)); // 附加
int bufferSize = 100;
char[] chars = new char[bufferSize];
int read = 0;
while ((read = br.read(chars, 0, bufferSize)) != -1) {
bw.write(chars, 0, read);
}
// 添加新的数据行
bw.append("Good lucky!" + r1);
vars.put("fileList",String.valueOf(newFileName));
System.out.println(newFileName+" This is new file name!");
bw.close();
br.close();
} catch (FileNotFoundException e) {
// File对象的创建过程中的异常捕获
e.printStackTrace();
} catch (IOException e) {
// BufferedWriter在关闭对象捕捉异常
e.printStackTrace();
}
原文:https://www.cnblogs.com/wangqian1002/p/15233060.html