配置文件中设置编码格式
conf = new Configuration(); try { conf.setDirectoryForTemplateLoading(new File(LOCAL_STORAGE_DIR)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } conf.setObjectWrapper(new DefaultObjectWrapper()); conf.setDefaultEncoding("utf-8");
同时在输出文件时设置对应格式
out = new OutputStreamWriter(new FileOutputStream(new File()), "utf-8"); template.process(root, out); out.flush();