javapoi3.16doc转换docx
时间: 2023-07-29 13:13:54 浏览: 136
您可以使用 Apache POI 库来转换 .doc 文件为 .docx 文件。以下是一个简单的 Java 代码示例:
```java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.hwpf.converter.WordToConverter;
import org.apache.poi.hwpf.usermodel.HWPFDocument;
public class DocToDocxConverter {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream(new File("input.doc"));
HWPFDocument doc = new HWPFDocument(fis);
XWPFDocument docx = WordToConverter.convert(doc);
FileOutputStream fos = new FileOutputStream(new File("output.docx"));
docx.write(fos);
fis.close();
fos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
```
这个代码片段将读取名为 "input.doc" 的 .doc 文件,将其转换为 XWPFDocument(.docx 格式),并将其写入名为 "output.docx" 的文件中。请确保您已经添加了 Apache POI 和 Apache POI HWPF 依赖项。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)