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.
String property = properties.getProperty("property.name");
But this is the code that I need.
Is there a function in Java that is equivalent to the GetPrivateProfileString of C?
No, there is no built-in initialization .INI file support in Java.
Java uses Properties files, which lays its data out like so:
propertyOne = 1
propertyTwo = 2
C uses Initialization files (.INI), which lays its data out in sections:
[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:
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.
INI files offer some more usefulness, but are not natively supported. A good 3rd party Java API for dealing with INI files is ini4j.
http://ini4j.sourceforge.net/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With