How to parse .plist file in Java?

前端 未结 2 1575
不知归路
不知归路 2020-12-19 13:58

I am trying to parse a .plist file in Java but not understanding how. I used a DOM parser but it gives an error and is not able to read .plist file

相关标签:
2条回答
  • 2020-12-19 14:33

    If I were you I'd use the PList class from code.google.com/xmlwise. It's specifically designed for dealing with .plist files.

    0 讨论(0)
  • 2020-12-19 14:39

    You will want to look at Apache Commons Configuration at http://commons.apache.org/proper/commons-configuration/, which offers a pList parser. Here's a snippet example:

            XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
            // load plist from classoath
            URL url = this.getClass().getClassLoader().getResource(systemConfigFile);
            plist.setFileName(url.getFile());
            plist.load();
            Iterator<String> keys = plist.getKeys();
            while (keys.hasNext()) {
                // do someting with the value
                plist.getString(keys.next());
            }
    
    0 讨论(0)
提交回复
热议问题