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>

最新文章

  1. IdentityServer4 使用OpenID Connect添加用户身份验证
  2. C# BS消息推送 负载均衡-SignalR&amp;Redis的配置(三)
  3. IBM Domino 9 出现 Domino Designer 您正在试图升级多用户安装。请获取正确的安装包以完成升级。 解决方案
  4. mssql手工注入及绕过术
  5. c# 支付宝查单补单
  6. 7.Mybatis关联表查询(这里主要讲的是一对一和一对多的关联查询)
  7. 39. Volume Rendering Techniques
  8. 【C#设计模式——创建型模式】工场方法模式
  9. MapReduce概述,原理,执行过程
  10. ExtJS 4 表单
  11. 转:在虚拟机中用NAT方式连接网络
  12. android花屏效果的实现(ViewPager的基本使用)
  13. Struts2实现文件下载
  14. [Codeforces375E]Red and Black Tree
  15. 【ABP】ABP跨域调用API时出现的问题
  16. win2003远程桌面怎么切换到多用户?
  17. diff 命令用法--如何打补丁【原创--学习笔记】
  18. JVM——Java HotSpot VM Options
  19. nginx 隐藏nginx版本号
  20. (1)MySQL(入门操作安装\基本指令)

热门文章

  1. Dynamics CRM 2015/2016新特性之三十三:有了ExecuteTransactionRequest,再也不用担心部分成功部分失败了
  2. ios获取摄像头
  3. Python的包package的导入与被导入(包的类和方法的导入,__init__()怎么写)
  4. 算法基础:BFS和DFS的直观解释
  5. Element-ui中为上传组件添加表单校验
  6. Saltstack_使用指南08_远程执行-返回程序
  7. Costco
  8. 如何将MagicaVoxel模型导入UE4中(1)
  9. luoguP3242 [HNOI2015]接水果
  10. pip 源切换至国内镜像