java 生成 word 文档 在mian方法中生成没问题,放到web上生成的word文档内容为空!
问题描述:
以下是我生成word的代码
try {
Configuration cfg = new Configuration();
cfg.setDefaultEncoding("UTF-8");
cfg.setOutputEncoding("UTF-8");
cfg.setLocale(Locale.US);
String tempDir = "D:/data/send";// 定义模板存放路径
String tempName = "mzl.ftl";// 定义模板名
String outputName = "D:/data/send/test.doc";// 定义输出文件名
cfg.setDirectoryForTemplateLoading(new File(tempDir));
Template temp = cfg.getTemplate(tempName,"UTF-8");
Map<String, Object> map = new HashMap<String, Object>();
map.put("shopcode", "yjw01");
map.put("auditpersonid", "yjw01");
String ssss="0010222233333332220"+(char)11;
map.put("licenseno",ssss);
try {
// 定义生成文件
File output = new File(outputName);
Writer writer = new FileWriter(output);
temp.process(map, writer);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
答
检查下你的路径还有权限,服务器上D:/data/send/文件夹存在么