JAVA Apache POI错误的文档写入输出
我在读一个文件,在段落中添加一些数据,然后在另一个文件中写出一个文档 我面临的问题是,输出文件不可读,我无法打开它,如果一个二进制文件打开它,我可以看到它没有正确的格式 每个字符的左侧都有一个JAVA Apache POI错误的文档写入输出,java,apache-poi,Java,Apache Poi,我在读一个文件,在段落中添加一些数据,然后在另一个文件中写出一个文档 我面临的问题是,输出文件不可读,我无法打开它,如果一个二进制文件打开它,我可以看到它没有正确的格式 每个字符的左侧都有一个?字符 你能就正在发生的事情给我一些建议吗? 编辑:代码保存功能 FileOutputStream out = null; try { // Add true to make the data append possible in output stream. out = new Fil
?
字符
你能就正在发生的事情给我一些建议吗?
编辑:代码保存功能
FileOutputStream out = null;
try {
// Add true to make the data append possible in output stream.
out = new FileOutputStream(filePath, true);
doc.write(out);
out.flush();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
out.close();
}
编辑文件:
File file = new File("muestra.doc");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
POIFSFileSystem fs = new POIFSFileSystem(fis);
HWPFDocument document = new HWPFDocument(fs);
Range range = document.getRange();
for (int i = 0; i < document.getParagraphTable().getParagraphs().size(); i++) {
Paragraph p = range.getParagraph(i);
p.insertBefore("£");
}
File File=new文件(“muestra.doc”);
FileInputStream fis=新的FileInputStream(file.getAbsolutePath());
POIFSFileSystem fs=新的POIFSFileSystem(fis);
HWPF文件=新的HWPF文件(fs);
范围=document.getRange();
对于(int i=0;i
使用英镑字符似乎导致POI以Unicode格式写出您的文件。也许您正在阅读的软件太旧了,无法理解这一点?这没有问题,因为编写任意字符会产生与FileOutputStream构造函数相同的输出,append=true-这看起来很奇怪,您不能只将一个文档文件附加到另一个文档文件的末尾。我每次都会删除该文件,我知道我可以把假,但这不是重点,问题是“?”字符在每个其他字符的左边。