简体   繁体   中英

XML file inside of Properties file in java

Is it possible to read xml file in a properties file in java? for example i have config.xml inside config.properties and get the value of the data inside the xml file like this?

 <?xml version="1.0" encoding="UTF-8"?>
-<Config>
 <Name>Goku</Name>
</Config>

You can store xml as String in your properties file and retrieve that value(not sure if this is what you want). See below.

config.properties

my.xml=<?xml version="1.0" encoding="UTF-8"?><Config><Name>Goku</Name></Config>

ReadXml.java:

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ReadXml{

    public static void main(String[] args) throws IOException {
        Properties prop = new Properties();
        InputStream input = new FileInputStream("config.properties");
        prop.load(input);

        System.out.println(prop.getProperty("my.xml"));
    }
}

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