I thought about creating my own, but there are many details to consider to make it 100% compatible with Java .properties files, so I'm asking first.
Not a Java guy, but from what I can see .properties files are similar to .INI files in disguise; it has name=value pairs, without section names. You can use Delphi's TStringList to work with that; it has the Names and Values properties.
For example, to read the following line from a .properties file:
MyProgramData=c:\documents and settings\DR\Application Data\MyApp
I can simply use:
var
SL: TStringList;
MyDataPath: string;
begin
SL := TStringList.Create;
try
SL.LoadFromFile('myapp.properties');
MyDataPath := SL.Values['MyProgramData'];
finally
SL.Free;
end;
// Do something with MyDataPath
end;
For the overly pedantic reader, I'm not suggesting that TStringList will allow you to use the full functionality of .properties files; it may, however, be enough for what you need to do. (As I said, I'm not a Java guy.)
There used to be a Java IDE called Gel. It was written in Delphi, and it was a good IDE, so I expect it was capable of working with property files. The author has discontinued work on the project. In his blog post describing the project's cancellation, he mentions being open to the prospect of making the project open source, but it never really took off. If you ask nicely, you might get the parts of that code you're looking for.
Be skeptical of any solution you find that uses TStrings
for its interface. Although that class has Names
and Values
properties that make it attractive as a class for working with key/value pairs, it won't be completely compatible with Java's property files. The reason is that Java allows "=" as a character in the key name, and the TStrings
class detects the end of a name and the start of a value by looking for the first "=" character in a string. Furthermore, Java property files can use ":" as the separator, and they can even use ordinary whitespace.