Java 如何使用selenium webdriver在另一个属性文件中使用build.properties的值

Java 如何使用selenium webdriver在另一个属性文件中使用build.properties的值,java,selenium,selenium-webdriver,webdriver,Java,Selenium,Selenium Webdriver,Webdriver,我正在使用eclipse for selenium webdriver。我已将URL分配给build.properties文件中的变量“webdriver.URL”。我创建了另一个名为“ExpectedResults.properties”的属性文件。我想在ExpectedResults.properties文件中使用build.properties的变量webdriver.url的值。可以使用吗。如果可能的话,你能告诉我会怎么样吗 提前谢谢 不清楚目标是什么。这里可能有两种情况: 1.假设“w

我正在使用eclipse for selenium webdriver。我已将URL分配给build.properties文件中的变量“webdriver.URL”。我创建了另一个名为“ExpectedResults.properties”的属性文件。我想在ExpectedResults.properties文件中使用build.properties的变量webdriver.url的值。可以使用吗。如果可能的话,你能告诉我会怎么样吗


提前谢谢

不清楚目标是什么。这里可能有两种情况:

1.假设“webdriver.url”变量中有url。 您可以将其写入第二个属性文件“ExpectedResults.properties”,如下所示

Properties prop = new Properties();
OutputStream output = null;
try {
    output = new FileOutputStream("ExpectedResults.properties");
    prop.setProperty("expected.url", webdriver.url);
    prop.store(output, null);

} catch (IOException io) {
    io.printStackTrace();
}
2您可以读取两个属性文件并比较URL-

Properties prop = new Properties();

InputStream input = null;
try {

input = new FileInputStream("filename.properties");

prop.load(input);

System.out.println(prop.getProperty("webdriver.url"));      
} 

catch (IOException ex) {

ex.printStackTrace();
} 

此处ExpectedResults.properties是一个文本文件。我给出的值为webdriver.url=。我的目标是在ExpectedResults.properties文本文件中使用此值。第一种情况是否可以在ExpectedResults.properties文本文件中使用?通过名称ExpectedResults.properties,它看起来像是属性文件。虽然它是文本文件,但它将包含形式为key=value的值。是的,第一种情况在这里是可能的。您可以在“ExpectedResults.properties”文件中设置url值,如上面第1点所示。稍后,您可以通过读取上面第2点中给出的文件,使用在“ExpectedResults.properties”中设置的url值读取属性与Selenium无关!这是一个Java问题。请更正您的标签。请发一些代码。