java读取docx

package document;

import interfaces.ICommon;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;

import common.AddTxt;

/**
 * 读取docx内容并写入txt
 * @author DanielCooger
 * <a href="mailto:[email protected]">daniel</a>
 */
public class Docx implements ICommon{
 //创建文件夹路径
 private String path = "d:\\doc";
 private String date = new SimpleDateFormat("yyyyMMddHHmmss")
   .format(new Date());
 //目标文件
 private String docx = "d:\\doc\\DOCX" + date + ".txt"; 

 /**
  * 读取docx文件内容
  */
 public boolean readText(String file) throws Exception {
  OPCPackage opcPackage = POIXMLDocument.openPackage(file);
  POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);
  String text = extractor.getText();
  System.out.println(text);
 }
}

你可能感兴趣的:(java,apache,Gmail)