To create a file, you first must obtain a file object first. You can get a file object as shown below:
/* * Relative path: */ var file = newFile("test.txt"); /* * Absolute path: Create test.txt file in helloWorld project. */ var file2 = newFile("/helloWorld/test.txt");
var file = promptSaveFile();
To write content in a file, you must obtain OutputStream object from the file object. Below is the method to get OutputStream object.
var file = ...; var outputStream = file.getOutputStream(); // Get OutpuStream
Once obtaining the stream, you can write content as below:
var outputStream = ...; outputStream.printf("%s(%df)\n", "Smith", 32);
Content of the file:
Smith(32)
Below is the example of printing out all the names of columns and data types:
var outputStream = ...; select(function(it){ return it.get("type") == "column"; }).each(function(it){ outputStream.printf("%s : %s\n", it.get("logical-name"), it.get("data-type")); }); outputStream.close();