• 通过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 ",filepath,true);
    for(int i=1;i<=50;i++){
    System.out.println("add ---------"+i);
    writeContent("test"+i+"@bbs-step.com,123456,e10adc39749ba59abbe56e057f20f883e"+" ",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();
    }
    }
    }
    }

  • 相关阅读:
    bzoj4105: [Thu Summer Camp 2015]平方运算
    bzoj4035: [HAOI2015]数组游戏
    bzoj1022: [SHOI2008]小约翰的游戏John
    bzoj4665: 小w的喜糖
    CodeChef:Little Elephant and Colored Coins
    bzoj4664: Count
    bzoj4498: 魔法的碰撞
    bzoj4230: 倒计时
    bzoj4532: [BeiJing2014 WinterCamp] 珠链
    python 画正态曲线
  • 原文地址:https://www.cnblogs.com/test123/p/7423155.html
Copyright © 2020-2023  润新知