Verify the file is exist on a location in jmeter using beanshell

JYOTI PRAKASH MALLICK :

I am trying to validating that a particular file exists or not in a folder using BeanShell sampler in jmeter.

import org.apache.commons.io.FileUtils;

String filename;
String tempFile;

if(vars.get("LogFile") != null) 
    {
    filename = vars.get("LogFile");
    log.info("File exist");
    }
else {
    log.info("File exist");
    }

I have defined LogFile in user-defined variable. And it is defined as LogFile : D:\Jmeter\Jmeter.log, currently, it is always returning true because it is not validating whether the file really exists or not.

user7294900 :

To check you need to add a file exists check

if (new File(filename).exists()) { 
    log.info("File exist");
} else {
    log.info("File not exist");
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=151303&siteId=1