用JAVA读取INI文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19674951/
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
Reading INI File in JAVA
提问by Innistrad
I was trying to get values from an INI File and I'm writing the code in Java. So far, I have read about this function and yes, it is returning values from the INI File.
我试图从 INI 文件中获取值,我正在用 Java 编写代码。到目前为止,我已经阅读了有关此函数的信息,是的,它正在从 INI 文件返回值。
String property = properties.getProperty("property.name");
But thisis the code that I need.
但是,这是我需要的代码。
Is there a function in Java that is equivalent to the GetPrivateProfileString of C?
Java中是否有等效于C的GetPrivateProfileString的函数?
采纳答案by hotforfeature
No, there is no built-in initialization .INI file support in Java.
不,Java 中没有内置的初始化 .INI 文件支持。
Java uses Properties files, which lays its data out like so:
Java 使用 Properties 文件,它的数据如下所示:
propertyOne = 1
propertyTwo = 2
C uses Initialization files (.INI), which lays its data out in sections:
C 使用初始化文件 (.INI),它将其数据分为几部分:
[Section]
propertyOne = 1
propertyTwo = 2
In Java, Properties don't have "sections", but can be divided up into sections by the same convention for naming packages:
在 Java 中,Properties 没有“部分”,但可以按照相同的包命名约定将其划分为多个部分:
section.propertyOne = 1
section.propertyTwo = 2
So you would call properties.getProperty("section.propertyOne");
, where in INI you call the section first and then the property instead of as one.
所以你会调用properties.getProperty("section.propertyOne");
, 在 INI 中,你首先调用该部分,然后调用属性而不是一个。
INI files offer some more usefulness, but are not natively supported. A good 3rd party Java API for dealing with INI files is ini4j.
INI 文件提供了更多的用处,但不受本机支持。一个很好的用于处理 INI 文件的第 3 方 Java API 是 ini4j。
The reason for this is that .INI is a Windows-specific file. You won't really find .INI files on other operating systems, and Java is a cross-platform language.
原因是 .INI 是 Windows 特定的文件。您不会在其他操作系统上真正找到 .INI 文件,而 Java 是一种跨平台语言。