通过Java构造参数列表

通过Java构造参数列表

 背景:我们在进行性能测试时,需要构造测试数据,即参数化文件,如下:

 

上面的文件内容,我们可以通过Java代码轻松实现,主要代码解释:

 

 

All 代码(其实我也看不懂,但是会改就行啦)

package file;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class FileWrite {

public static void main(String[] args) {
String filepath= "C:\\Users\\lixiaojuan\\Desktop\\lr\\末班\\test2.txt";
checkFile(filepath);
writeContent("name,pwd,salt\n",filepath,true);
for(int i=1;i<=50;i++){
System.out.println("add ---------"+i);
writeContent("test"+i+"@bbs-step.com,123456,e10adc39749ba59abbe56e057f20f883e"+"\n",filepath,true);
}
}


/**
* 写入内容到文件
*
* @param number
* @param filename
* @return
*/
public static boolean writeContent(String c, String path, boolean isAppend) {
File f = new File(path);
try {
FileOutputStream fos = new FileOutputStream(path, isAppend);
OutputStreamWriter writer = new OutputStreamWriter(fos, "UTF-8");
writer.write(c);
writer.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}

public static void checkFile(String filepath) {
File f = new File(filepath);
if (!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return;
} else {
f.delete();
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

 

posted @ 2017-08-24 15:04 Winnie~ 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值