word转txt
2024-10-19 00:32:00
import org.apache.poi.hwpf.extractor.WordExtractor;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class Doc2Text {
Doc2Text() throws IOException {
var fojingPath = "/home/weiyinfu/Desktop/佛经";
var targetPath = "/home/weiyinfu/Desktop/fojing";
if (!Files.exists(Paths.get(targetPath))) {
Files.createDirectory(Paths.get(targetPath));
}
Files.list(Paths.get(fojingPath)).forEach(docPath -> {
try {
InputStream cin = Files.newInputStream(docPath);
WordExtractor extractor = new WordExtractor(cin);
cin.close();
String content = extractor.getText();
String filename = docPath.getFileName() + ".txt";
var cout = Files.newBufferedWriter(Paths.get(targetPath).resolve(filename), StandardOpenOption.CREATE);
cout.write(content);
cout.close();
} catch (IOException e) {
e.printStackTrace();
}
});
}
public static void main(String[] args) throws IOException {
new Doc2Text();
}
}
需要POI
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>4.1.0</version>
</dependency>
最新文章
- IdentityServer4 使用OpenID Connect添加用户身份验证
- C# BS消息推送 负载均衡-SignalR&;Redis的配置(三)
- IBM Domino 9 出现 Domino Designer 您正在试图升级多用户安装。请获取正确的安装包以完成升级。 解决方案
- mssql手工注入及绕过术
- c# 支付宝查单补单
- 7.Mybatis关联表查询(这里主要讲的是一对一和一对多的关联查询)
- 39. Volume Rendering Techniques
- 【C#设计模式——创建型模式】工场方法模式
- MapReduce概述,原理,执行过程
- ExtJS 4 表单
- 转:在虚拟机中用NAT方式连接网络
- android花屏效果的实现(ViewPager的基本使用)
- Struts2实现文件下载
- [Codeforces375E]Red and Black Tree
- 【ABP】ABP跨域调用API时出现的问题
- win2003远程桌面怎么切换到多用户?
- diff 命令用法--如何打补丁【原创--学习笔记】
- JVM——Java HotSpot VM Options
- nginx 隐藏nginx版本号
- (1)MySQL(入门操作安装\基本指令)
热门文章
- Dynamics CRM 2015/2016新特性之三十三:有了ExecuteTransactionRequest,再也不用担心部分成功部分失败了
- ios获取摄像头
- Python的包package的导入与被导入(包的类和方法的导入,__init__()怎么写)
- 算法基础:BFS和DFS的直观解释
- Element-ui中为上传组件添加表单校验
- Saltstack_使用指南08_远程执行-返回程序
- Costco
- 如何将MagicaVoxel模型导入UE4中(1)
- luoguP3242 [HNOI2015]接水果
- pip 源切换至国内镜像