macos 如何从 Java 读取 OSX .plist 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1749197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:32:51  来源:igfitidea点击:

How to read OSX .plist files from Java?

javamacosplist

提问by nonamelive

How to read OSX .plist filesfrom Java?

如何从 Java读取 OSX .plist 文件

回答by Erik

Imho running a commandline tool from Java is not quite the "best way to do the job".

Imho 从 Java 运行命令行工具并不是“完成这项工作的最佳方式”。

There are several much better ways to deal with binary plist in JAVA: That one I prefere is an usefull little project by Daniel Dreibrodt at: google project hosting

有几种更好的方法来处理 JAVA 中的二进制 plist:我更喜欢的是 Daniel Dreibrodt 的一个有用的小项目:谷歌项目托管

You can also use Apache Commons Configuration(which API is supporting the Property List format). More information about the history of the .plist-format on OSX (which version introduced which format) I wrote up on my blog

您还可以使用Apache Commons Configuration(该 API 支持属性列表格式)。有关 OSX 上 .plist 格式历史的更多信息(哪个版本引入了哪种格式)我在我的博客上写过

Update:There is a new project hosted at source forge called Property List Library, that shall be able to read AND write .plist- I have not tested it, but it sounds interesting.

更新:在 source forge 上托管了一个名为Property List Library的新项目,它应该能够读写 .plist - 我没有测试过它,但听起来很有趣。

回答by jitter

I guess you refer to the plist format used on Mac starting with Mac OS X (and not the NeXTSTEP or GNUstep format).

我猜你指的是从 Mac OS X 开始的 Mac 上使用的 plist 格式(而不是 NeXTSTEP 或 GNUstep 格式)。

  1. Determine if the file is in XML or binary format
  2. If in binary format use the plutilcommand-line-utility to convert file to xml format
  3. Now you have the file in xml format, use any java-xml-library to handle the plist
  1. 确定文件是 XML 格式还是二进制格式
  2. 如果是二进制格式,请使用plutil命令行实用程序将文件转换为 xml 格式
  3. 现在你有了 xml 格式的文件,使用任何 java-xml-library 来处理 plist

回答by jornane

You can use this library:

你可以使用这个库:

Property List Library (SourceForge)

属性列表库 (SourceForge)

It will read property list files to objects and vice versa.

它会将属性列表文件读取到对象,反之亦然。

回答by Paul Jowett

These days the Java Preferences API on a Mac automatically uses plist files and they are in binary format. You might be able to read the plist automatically simply by reading the preferences at the "node".

现在,Mac 上的 Java Preferences API 自动使用 plist 文件,它们是二进制格式。您可以通过阅读“节点”上的首选项来自动读取 plist。

I hope that helps.

我希望这有帮助。