如何将word的内容提取出来转成txt

public static void main(String[] args) throws Exception{


File filesDir = new File("d:\\doc\\");      

File[] files = filesDir.listFiles();        //读取文件夹中的文件
                                                        // 遍历文件
for (int i = 0; i < files.length; i++) {
// 获取文件名
String fileName = files[i].getName();     

String Name=fileName.substring(0,fileName.lastIndexOf("."));
// 判断文件是否为doc类型的文件
if (fileName.substring(fileName.lastIndexOf("."))
.equals(".doc")) {

WordExtractor extractor = new WordExtractor(new FileInputStream ("d:\\doc\\"+fileName));
String str = extractor.getText();

BufferedWriter writer = new BufferedWriter(new FileWriter("d:\\testfolder11\\" + Name+ ".txt"));
writer.write(str.trim());
extractor.close();
writer.close();

}
}


}

你可能感兴趣的:(如何将word的内容提取出来转成txt)