读取word文档报错 错误信息 Invalid header signature; read 0x3C0A0D0A0DBFBBEF, expected 0xE11AB1A1E011CFD0
private final static String filePath = "D:/Test.doc";
public static void main(String[] args) throws FileNotFoundException, IOException {
FileInputStream stream = new FileInputStream(filePath);
System.out.println(stream);
HWPFDocument doc = new HWPFDocument(new FileInputStream(filePath));
System.out.println(doc);
}
解决办法:将读取那个文档,另存为一个文件就好,重新读取
private final static String filePath = "D:/TestNew.doc";
public static void main(String[] args) throws FileNotFoundException, IOException {
FileInputStream stream = new FileInputStream(filePath);
System.out.println(stream);
HWPFDocument doc = new HWPFDocument(new FileInputStream(filePath));
System.out.println(doc);
}
本文介绍了一种解决在Java中使用Apache POI读取Word文档时遇到的Invalidheadersignature错误的方法。通过将文档另存为新文件,可以有效避免此问题,确保文档能够被正确读取。
1471

被折叠的 条评论
为什么被折叠?



