java读取docx

liben00 2010-06-08

package document;

import interfaces.ICommon;

import java.text.SimpleDateFormat;

importjava.util.Date;

importorg.apache.poi.POIXMLDocument;

importorg.apache.poi.POIXMLTextExtractor;

importorg.apache.poi.openxml4j.opc.OPCPackage;

import org.apache.poi.xwpf.extractor.XWPFWordExtractor;

import common.AddTxt;

/**

*读取docx内容并写入txt

*@authorDanielCooger

*<ahref="mailto:[email protected]">daniel</a>

*/

publicclassDocximplementsICommon{

//创建文件夹路径

privateStringpath="d:\\doc";

privateStringdate=newSimpleDateFormat("yyyyMMddHHmmss")

.format(newDate());

//目标文件

 private String docx = "d:\\doc\\DOCX" + date + ".txt"; 

 /**

*读取docx文件内容

*/

publicbooleanreadText(Stringfile)throwsException{

OPCPackageopcPackage=POIXMLDocument.openPackage(file);

POIXMLTextExtractorextractor=newXWPFWordExtractor(opcPackage);

Stringtext=extractor.getText();

System.out.println(text);

}

}

相关推荐