word转txt
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>
word转txt的更多相关文章
- word和.txt文件转html 及pdf文件, 使用poi jsoup itext心得
word和.txt文件转html 及pdf文件, 使用poi jsoup itext心得本人第一次写博客,有上面不足的或者需要改正的希望大家指出来,一起学习交流讨论.由于在项目中遇到了这一个问题,在 ...
- iOS 应用中加载文档pdf/word/txt
一.加载PDF文档:应用内打开文档.手机中其他应用打开文档 Demo 首先拖入一个文档pdf.word.txt,打开不同的文档知识 文件名字.类型修改即可 #import "ReadView ...
- ASP.NET MVC在线预览Excel、Word、TXT、PDF文件
代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syste ...
- WPF: 读取XPS文件或将word、txt文件转化为XPS文件
读取XPS格式文件或将doc,txt文件转化为XPS文件,效果图如下: 1.XAML页面代码: <Window x:Class="WpfWord.MainWindow" xm ...
- WFP: 读取XPS文件或将word、txt文件转化为XPS文件
读取XPS格式文件或将doc,txt文件转化为XPS文件,效果图如下: 1.XAML页面代码: <Window x:Class="WpfWord.MainWindow" ...
- 2、Python djang 框架下的word Excel TXT Image 等文件的下载
2.python实现文件下载 (1)方法一.直接用a标签的href+数据库中文件地址,即可下载.缺点:word excel是直接弹框下载,对于image txt 等文件的下载方式是直接在新页面打开. ...
- python 将word另存为txt
import os import os.path from win32com import client as wc c=[] rootdir=["d:/77"] #以该路径为 ...
- Java实现Word/Pdf/TXT转html
引言: 最近公司在做一个教育培训学习及在线考试的项目,本人主要从事网络课程模块,主要做课程分类,课程,课件的创建及在线学习和统计的功能,因为课件涉及到多种类型,像视频,音频,图文,外部链接及文档类型. ...
- js 读取word和txt(react版) + 正则分割段落
show the code 前提:需要mammoth包~ import React, { useState, useReducer } from 'react'; import { Button, A ...
- MarkDown语法记录,还在用word,txt编写项目文档吗?
开始之前 是不是在github上看项目的时候第一眼就要看项目介绍? 是不是经常在某些项目的代码里面看到一个README.MD文档 却不知道怎么写? 你是不是不知道,反正我是的. 作为一个程序员,可能写 ...
随机推荐
- Java 数学操作类
数学操作类 Math类 数学计算操作类 类属性值 Math.E ^ Math.PI 圆周率 类方法 Math类中,一切方法都是 static 型,因为Math类中没有普通属性. round() 方法 ...
- CodeWarrior IDE烧写介绍
点击Flash烧写 选择芯片系列 下面将以PPC8548 NOR Flash烧写为例 默认配置文件目录:C:\Program Files (x86)\Freescale\CodeWarrior PA ...
- apache jmeter 使用
======================= 插件 ======================= 在JMeter 中很多东西都是基于插件技术的, 所以扩展性非常好, 比如下面这些东西都是插件: 1 ...
- Sublime操作
快速搭建HTML模版:左下角的纯文本编程HTML语言,然后输出!(感叹号)或者html:5,再按Tab键. 快速创建html标签: div#top>(div.top-left>div.li ...
- configure.ac文件和Makefile.am文件 编译
在编译安装openvpn 项目时遇到,其编译过程如下:生成 configure 可执行文件 make && make install ; . aclocal . autoconf . ...
- Linux同一机器设置多个IP2019-7-6
1.临时增加 1)先查看目前的网卡信息 [root@study ~]# ifconfigeno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAS ...
- c#_sort排序函数的返回值
C# List.Sort函数的返回值 值 含义 小于零 left在right的前面 零 位置不变 大于零 right在left的前面 示例: 本测试结果在unity3d 和纯C#环境下执行. List ...
- 13.Java基础_数组内存图
单个数组内存图 new int[3]: 在堆内存里申请一块空间存储int类型的变量(初始化时值都为0) int[] array: 在栈内存申请一块内存存储堆内存里数组的首地址 array[i]: 通过 ...
- 类数组(Array-like)对象应用
类数组(Array-like)对象 slice 方法可以用来将一个类数组(Array-like)对象/集合转换成一个新数组.你只需将该方法绑定到这个对象上. 一个函数中的 arguments 就是一 ...
- luoguP4151 [WC2011]最大XOR和路径
题意 这题有点神啊. 首先考虑注意这句话: 路径可以重复经过某些点或边,当一条边在路径中出现了多次时,其权值在计算 XOR 和时也要被计算相应多的次数 也就是说如果出现下面的情况: 我们可以通过异或上 ...