How to read properties from xml file with java?

后端 未结 7 1378
独厮守ぢ
独厮守ぢ 2021-01-08 00:51

I have the following xml file:


    
        
        

        
7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-08 01:38

    This is trivial, assuming you're willing to re-write your properties file into the standard Java format. Assume you have the following in a file called props.xml:

    
    
        This is a comment
        A
        B
        C
        D
        E
        F
    
    

    Then read properties from the file like this:

    java.util.Properties prop = new Properties();
    prop.loadFromXML(new FileInputStream("props.xml"));
    System.out.println(prop.getProperty("propF"));
    

提交回复
热议问题