Does anybody already made this? Because it is possible to use the JavaRB.cfc made by mr. Paul Hastings, but it gives the possibility to read from a properties file, no to write into it?
You can use the underlying Java Properties class to do this pretty easily:
<cfscript>
fos = CreateObject("java","java.io.FileOutputStream").init(ExpandPath("out.properties"));
props = CreateObject("java","java.util.Properties");
props.setProperty("site","stackoverflow.com");
props.setProperty("for","Stephane");
props.store(fos,"This is a properties file saved from CF");
</cfscript>
Although the format of a properties file is pretty simple, so you could also use the ColdFusion file functions to write a properties file:
<cfscript>
props={"site"="stackoverflow.com","for"="Stephane"};
crlf=chr(13) & chr(10);
propFile = FileOpen(ExpandPath("out2.properties"),"write");
FileWrite(propFile,"##This is a properties file saved from CF" & crlf );
for(prop in props){
FileWrite(propFile,prop & "=" & props[prop] & crlf);
}
FileClose(propFile);
</cfscript>
It probably comes down to where you have the data stored. If it's in a struct, it may be easier to use CF. If it's in a Java Properties object, then the code above is pretty minimal
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