话不多说,直接上代码
service层代码。
public String exportDoc(String text, String wordName) {
String dateUrl = this.StringDate();
FileUtils.createDirectory(reportDir);
File wordUrl = new File(reportUrl+ dateUrl+wordName + ".docx");
File wordDir = new File(reportDir+ dateUrl+wordName + ".docx");
OutputStream out = null;
try {
out = new FileOutputStream(wordDir);
out.write(text.getBytes());
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
return wordUrl.toString();
}
通过felie流去创建文件,当中的,StringDate 只是为了防止生成的名字重复,所以方法当中是直接获取当前时间的,test 是我们通过其他解析完的数据为了放入,wordName是用户希望的文档名称。通过文件流去写入数据