Java 有没有办法让ApachePOI通过FileOutputStream在UTF-8中写入.doc文件?
在将Apache POI与Java 有没有办法让ApachePOI通过FileOutputStream在UTF-8中写入.doc文件?,java,encoding,apache-poi,Java,Encoding,Apache Poi,在将Apache POI与FileOutputStream一起使用时,有没有办法为.doc文件设置UTF-8编码 这是创建word文档实例的代码: wordDocument = createWordDocument(); 这是将数据写入物理文件的代码: File resultFile = new File(fileLocation + fileName); resultFile.getParentFile().mkdirs(); FileOutputStream out = new Fil
FileOutputStream
一起使用时,有没有办法为.doc文件设置UTF-8
编码
这是创建word文档实例的代码:
wordDocument = createWordDocument();
这是将数据写入物理文件的代码:
File resultFile = new File(fileLocation + fileName);
resultFile.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(resultFile);
wordDocument.write(out);
UTF-8
是所有字符串io的Java默认值。您可以发布一个示例,说明如何写入XWPFDocument并将结果写入xml文件。createNewFile()
在这里不仅冗余而且浪费new FileOutputStream(…)
已经做到了这一点,现在您正在强制它删除您刚才创建的文件。@petermm这是我将wordDocument的内容写入out文件的地方:wordDocument.write(out)代码>。有一个XML结构的字符串
,它被解析并写入XWPFDocument
。您也想这样吗?XWPFDocument将编写一个.docx文件,它是一个包含内部XML文件的Zip文件。为什么需要控制这些xml文件中文本的编码?或者你的意思是不同的?docx不是纯文本,所以它本身没有编码。它是一个压缩文件,因此是二进制格式,只有压缩文件中的文件是XML。
File resultFile = new File(fileLocation + fileName);
resultFile.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(resultFile);
wordDocument.write(out);