poi doc转docx
时间: 2023-09-10 17:11:08 浏览: 217
poi转docx包
可以使用Apache POI库来将doc文件转换成docx文件。下面是一个简单的Java代码示例:
```java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.hwpf.converter.WordToFoConverter;
import org.apache.poi.hwpf.HWPFDocument;
public class DocToDocxConverter {
public static void main(String[] args) {
String docFilePath = "path/to/document.doc";
String docxFilePath = "path/to/document.docx";
try {
FileInputStream inputStream = new FileInputStream(docFilePath);
HWPFDocument document = new HWPFDocument(inputStream);
XWPFDocument documentOut = new XWPFDocument();
WordToFoConverter wordToFoConverter = new WordToFoConverter(documentOut);
wordToFoConverter.processDocument(document);
FileOutputStream outputStream = new FileOutputStream(docxFilePath);
documentOut.write(outputStream);
outputStream.close();
System.out.println("File converted successfully");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
```
请确保在代码中替换文档路径。这个示例假定你已经正确地安装了Apache POI库。
阅读全文