Is there something equivalent to plist files in Android like we have in iOS?
When programming iOS apps we can have data in a plist file then read it in/out in a matter of 开发者_运维问答one-two lines with NSDictionary. Does something like this exists on Android? I have already made an app on iOS with a plist file containing a couple of hundred entries. That is just normal XML isn't it? So I can parse the file with SAX/DOM Java parser?
Plist files exist in one of three forms:
- NeXTSTEP format (which looks a lot like JSON). This is deprecated.
- XML format (which you can parse on any platform very easily)
- Binary format (which is not documented by Apple but saves space compared to the XML format)
If the plist file you want to parse is in NeXTSTEP or XML format, it is easy to build a parser for it using existing tools on most platforms. In the case of the XML format, yes you can use Java's inbuilt parser.
If the plist file is binary, however, you will have to either roll your own parser or use an existing third-party class. One exists at http://www.java2s.com/Open-Source/Java-Document/Swing-Library/jide-oss-2.8.3/com/jidesoft/plaf/aqua/BinaryPListParser.java.htm, but I haven't used it myself so I can't vouch for its accuracy/quality/performance.
In addition to the other answers presented here, I would look at the nature of the data you need in your plist file. If your plist file is just a flat NSDictionary of string values, rather than a dictionary of structured value, then you do have the option of using a Java Properties object:
Android Java Properties
Again, this doesn't help you if your requirements include a fully structured equivalent to plist files. But if you just need a simple dictionary of keyed values stored in a text file, java.util.Properties is the way to go.
ultimately a plist is just a xml doc with a specific format. It shouldn't be to hard to make your own in java using a parser. also you will be able to taylor the xml file to fit your specific needs.
精彩评论