1. 程式人生 > 其它 >jmeter beanshell 讀寫檔案

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.寫入中文會有亂碼