我正在为Java中的遗留应用程序写入替换。 其中一个要求是使用旧应用程序的ini文件必须按原样读取到新的Java应用程序中。 这个ini文件的格式是通用的窗口样式,标题部分和键=值对,使用#作为注释的字符。
我尝试使用Java中的Properties类,但是当不同标题之间有名称冲突时,这当然不起作用。
所以问题是,读这个INI文件和访问密钥最简单的方法是什么?
I am writing a drop-in replacement for a legacy application in Java. One of the requirements is that the ini files that the older application used have to be read as-is into the new Java Application. The format of this ini files is the common windows style, with header sections and key=value pairs, using # as the character for commenting.
I tried using the Properties class from Java, but of course that won't work if there is name clashes between different headers.
So the question is, what would be the easiest way to read in this INI file and access the keys?
最满意答案
我使用的图书馆是ini4j 。 它是轻量级的,并轻松解析ini文件。 此外,它不会对10,000个其他jar文件使用任何深奥的依赖,因为其中一个设计目标是仅使用标准的Java API
这是一个关于如何使用库的例子:
Ini ini = new Ini(new File(filename)); java.util.prefs.Preferences prefs = new IniPreferences(ini); System.out.println("grumpy/homePage: " + prefs.node("grumpy").get("homePage", null));The library I've used is ini4j. It is lightweight and parses the ini files with ease. Also it uses no esoteric dependencies to 10,000 other jar files, as one of the design goals was to use only the standard Java API
This is an example on how the library is used:
Ini ini = new Ini(new File(filename)); java.util.prefs.Preferences prefs = new IniPreferences(ini); System.out.println("grumpy/homePage: " + prefs.node("grumpy").get("homePage", null));更多推荐
发布评论