???????java project??????freemarker.jar?? ???????????汾??freemarker-2.3.20 ?汾
????java?????????£?

????test.ftl???
name : ${name}
age : ${age}
test??
package com.freemarker;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class Test {
public static void main(String[] args) throws IOException?? TemplateException {
//1.???????????Cofiguration
Configuration cfg = new Configuration();
//2.????????????
//??1??src???μ?????template??src?£?
//cfg.setDirectoryForTemplateLoading(new File("src/template"));
//??2??????·????template??src?£?
//cfg.setDirectoryForTemplateLoading(new File(
//      "D:/cpic-env/workspace/javaFreemarker/src/template"));
//cfg.setDirectoryForTemplateLoading(new File("src/template"));
//??3?????????μ?????template/main??????£?--???
cfg.setDirectoryForTemplateLoading(new File("template/main"));
//cfg.setObjectWrapper(new DefaultObjectWrapper());
//?????壨template??
Template template = cfg.getTemplate("test.ftl");
//????????????Map??
Map<String?? String> root = new HashMap<String?? String>();
root.put("name"?? "cxl");
root.put("age"?? "25");
//????????????????????????????????
Writer out = new OutputStreamWriter(System.out);
//StringWriter out = new StringWriter();
//System.out.println(out.toString());
//?????????????????+???=?????
template.process(root?? out);
out.flush();
}
}
???????н????
????name : cxl
????age : 25