When generating SQL, it is often desirable to have the script to create an entire schema in a single file, both to maintain consistency and to make the handling and execution simpler. When generating Java, on the other hand, it is generally the case that you would like each class to be placed in an individual file, named the same as the class it represents. The write keyword allows you to do just that.
By default, Intercalate sends the text generated by merging a template and dictionary to the standard output stream. This conveniently permits it to work with the output redirection available in Unix and Windows. Whenever Intercalate encounters a write keyword in a template, it constructs a file name from the following key and thereafter sends output to that file. If the write keyword appears without a following key, subsequent text once more is sent to the standard output stream.
The key used for generating file names is handled slightly differently from other keys. In our example, since the value of the table key is a simple string and not a structure, ordinarily the compound key table.java would fail lookup and return an empty string. When used with the write keyword, however, the file name generated is the value of the last successful lookup concatenated with the rest of the key. In our example, the file names will be Person.java and Vehicle.java.