在beanshellsampler JMeter中的“文件f =新文件(“//开发/测试”)”

vql8enpb  于 2022-11-09  发布在  Shell
关注(0)|答案(1)|浏览(88)

在Jenkins中配置的beanshellsampler JMeter中,尝试使用java.io.File“File f = new File(“//DEV/Test”)”从文件路径获取文件,当尝试获取绝对路径时,仅获取“/Dev/Test”。缺少一个“/”。

String folderPath = "//Dev/Test";

# oneway

File folder = new File(folderPath);
folder.toAbsolutePath(); //output :: /Dev/Test

# Secondway

Path p1 = Paths.get(foldertoString, new String[0]);
File pathtoFile = p1.toFile(); 
String[] fn = pathtoFile.list();
// output : path is not correct
k97glaaz

k97glaaz1#

它没有丢失,/ is the root of the Linux file system,没有必要在那里有一个额外的斜线。
还应注意,从JMeter 3.1开始,建议使用JSR223测试元素和Groovy语言编写脚本,因此请考虑在下一个可用的机会进行迁移。
有关JMeter中的Groovy脚本的更多信息:Apache Groovy: What Is Groovy Used For?

相关问题