我有一个问题,我如何能够将我的方式与文件连接起来
import java.util.Properties
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def path = groovyUtils.projectPath
Properties properties = new Properties();
File propertiesFile = (path + JsonConfig.properties);
log.info propertiesFile
propertiesFile.withInputStream {
stream -> properties.load(stream);
}
iterator = properties.keySet().iterator();
while(iterator.hasNext()) {
key = iterator.next();
value = properties[key];
testRunner.testCase.testSuite.project.setPropertyValue(key, value);
}
错误:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'E:\JsonConfig.properties' with class 'java.lang.String' to class 'java.io.File' error at line: 9
答案 0 :(得分:0)
path + JsonConfig.properties
似乎是String
。您可能想要调用File
构造函数。替换:
File propertiesFile = (path + JsonConfig.properties);
使用:
File propertiesFile = new File(path + JsonConfig.properties);