I was recently asked how to write some results from a script into a file on the file system. Most examples for that problem for Java Script that can be found in the net, are targeting script engines that run in a browser. They will not work in medini. See also the article "Using Script to output a txt, csv, xml, or xlsx file" that was opened by Tony a while back.
So fortunately - as mentioned there - we can script Java in medini so can utilize the complete Java API which, beside other things, has full access to the file system.
The simples function that takes a string and writes it to a dedicated text file looks like this:
/*
* Helper to store the text into a file using the *default* character encoding.
*/
function writeToFile(text, fileName) {
var file = new java.io.File(fileName);
var writer = new java.io.FileWriter(file);
writer.write(text);
writer.close();
}
Note that Java has capabilities to define the file character encoding which we don't use in this example. So the default platform encoding is used.
Happy Scripting
Jan