我正在嘗試複製並重命名本地文件機器(Win 7)在JMeter 3.0(Java v1.8)中使用Bean Shell Sampler。這個想法是創建一個具有唯一名稱的新文件,並將該名稱保存爲一個變量,可用於代替FTP PUT請求中的文件名。JMeter Bean Shell Sampler錯誤「...當複製文件時,在類'java.nio.file.Paths」中找不到靜態方法get(java.lang.String)
這裏是我使用複製和重命名代碼:
import java.text.*;
import java.nio.file.StandardCopyOption.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
String filename = new SimpleDateFormat("dd-MM-yyyy_hh:mm:ss").format(new Date())+".xlsx";
log.info(filename);
Path source = Paths.get("C:/dropfile/qatp/QATP_GuestRecords.xlsx");
Path target = Paths.get("C:/dropfile/qatp/"+filename);
Files.copy(source, target, REPLACE_EXISTING);
錯誤我收到在日誌中:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.text.; import java.nio.file.StandardCopyOption.; import java.io.IO . . . '' : Typed variable declaration : Error in method invocation: Static method get( java.lang.String) not found in class'java.nio.file.Paths'
我一直在尋找的答案,這個問題並遇到了一個solution where the suggestion was: 「我的猜測是,它的問題是它沒有填充可變參數。試試:
Path target = Paths.get(filename, new String[0]);"
我試圖通過修改我的代碼如下所示此解決方案:
import java.text.*;
import java.nio.file.StandardCopyOption.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
String filename = new SimpleDateFormat("dd-MM-yyyy_hh:mm:ss").format(new Date())+".xlsx";
log.info(filename);
Path source = Paths.get("C:/dropfile/qatp/QATP_GuestRecords.xlsx", new String[0]);
Path target = Paths.get("C:/dropfile/qatp/"+filename, new String[0]);
Files.copy(source, target, REPLACE_EXISTING);
而且收到此錯誤:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.text.; import java.nio.file.StandardCopyOption.; import java.io.IO . . . '' : Typed variable declaration : Method Invocation Paths.get
有誰知道爲什麼我打這個錯誤,如何解決呢?