简体   繁体   English

Android中的plist文件是否与iOS中的相同?

[英]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. 在编写iOS应用程序时,我们可以将数据放在plist文件中,然后使用NSDictionary在一两行中读取/读出。 Does something like this exists on Android? Android上是否存在类似的内容? I have already made an app on iOS with a plist file containing a couple of hundred entries. 我已经在iOS上创建了一个app,其中包含一个包含几百个条目的plist文件。 That is just normal XML isn't it? 那只是普通的XML不是吗? So I can parse the file with SAX/DOM Java parser? 所以我可以使用SAX / DOM Java解析器解析文件?

Plist files exist in one of three forms: Plist文件以三种形式之一存在:

  • NeXTSTEP format (which looks a lot like JSON). NeXTSTEP格式(看起来很像JSON)。 This is deprecated. 这已被弃用。
  • XML format (which you can parse on any platform very easily) XML格式(您可以非常轻松地在任何平台上解析)
  • Binary format (which is not documented by Apple but saves space compared to the XML format) 二进制格式(Apple没有记录,但与XML格式相比节省了空间)

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. 如果要解析的plist文件是NeXTSTEP或XML格式,则可以使用大多数平台上的现有工具为其构建解析器。 In the case of the XML format, yes you can use Java's inbuilt parser. 对于XML格式,是的,您可以使用Java的内置解析器。

If the plist file is binary, however, you will have to either roll your own parser or use an existing third-party class. 但是,如果plist文件是二进制文件,则必须滚动自己的解析器或使用现有的第三方类。 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. 一个存在于http://www.java2s.com/Open-Source/Java-Document/Swing-Library/jide-oss-2.8.3/com/jidesoft/plaf/aqua/BinaryPListParser.java.htm ,但我没有我自己用它,所以我不能保证它的准确性/质量/性能。

In addition to the other answers presented here, I would look at the nature of the data you need in your plist file. 除了这里提供的其他答案之外,我还会看一下plist文件中所需数据的性质。 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: 如果plist文件只是字符串值的平面NSDictionary,而不是结构化值的字典,那么您可以选择使用Java Properties对象:

Android Java Properties Android Java属性

Again, this doesn't help you if your requirements include a fully structured equivalent to plist files. 同样,如果您的要求包含与plist文件完全相同的结构,这对您没有帮助。 But if you just need a simple dictionary of keyed values stored in a text file, java.util.Properties is the way to go. 但是如果你只需要一个存储在文本文件中的键控值的简单字典,java.util.Properties就是你要走的路。

ultimately a plist is just a xml doc with a specific format. 最终plist只是一个具有特定格式的xml doc。 It shouldn't be to hard to make your own in java using a parser. 使用解析器在java中创建自己的应该不是很难。 also you will be able to taylor the xml file to fit your specific needs. 您也可以使用xml文件来满足您的特定需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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