简体   繁体   中英

How can i change a .properties file into an XML file?

How can i change a .properties file into an XML file?

I have developed an automation framework which reads a central config file which is of type .properties file. My framework uses the Java programming language and i need a way to alter the values contained within the .properties file via MS TFS.

I know that within MS TFS you can create global variables and then feed the information / data to an xml file, is there a way to change a .properties file into an XML file and in turn also read those values within my JAVA framework?

Example Java code which reads the .properties file:

public WebDriver getDriver() throws Exception {
    try {
        Properties p = new Properties();
        FileInputStream fi = new FileInputStream(Base_Page.getConstant(Constant.CONFIG_PROPERTIES_DIRECTORY));
        p.load(fi);

        String browserName = p.getProperty("browser");
        switch (browserName) {

Properties file:

在此处输入图片说明

This link instructs you how to alter values stored within the TFS using an XML file.

An XML-based property file looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
  <comment>Your comment here</comment>
  <entry key="your.property.key">Your property value</entry>
  <entry key="your.second.property.key">Your second property value</entry>
</properties>

You can store them with Properties.storeToXML​(OutputStream os, String comment) and load them with Properties.loadFromXML​(InputStream in) :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM