我是将word另存为xml文件,用FreeMarker标签处理,然后生成的word文件,怎么将他设置为只读呢。
最后的执行语句是这样的:Map<String, Object> dataMap = new HashMap<String, Object>();
getData(dataMap);
// 设置模本装置方法和路径,FreeMarker支持多种模板装载方法。可以重servlet,classpath,数据库装载,
// 模板是放在com.havenliu.document.template包下面
configuration.setClassForTemplateLoading(this.getClass(),
"/com/havenliu/document/template");
Template t = null;
try {
// test.ftl为要装载的模板
t = configuration.getTemplate("test.xml");
} catch (IOException e) {
e.printStackTrace();
}
// 输出文档路径及名称
File outFile = new File("D:/files/outfile.doc");
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outFile),"utf-8"));
} catch (Exception e1) {
e1.printStackTrace();
} try {
t.process(dataMap, out);
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
用file的