Java tutorial
//package com.java2s; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.Map; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; public class Main { public static void execute(final String templateDirName, final String templateFileName, final Map param, final OutputStream out) throws IOException, TemplateException { // create configuration Configuration cfg = new Configuration(); cfg.setDirectoryForTemplateLoading(new File(templateDirName)); // get template Template temp = cfg.getTemplate(templateFileName); // execute temp.process(param, new OutputStreamWriter(out)); // temp.process(new SampleBean(), new OutputStreamWriter(out)); // flush out out.flush(); } }