package com.github.tangyi.exam.service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
public class TestWord {
public static void main(String[] args) {
File file = new File("E:\\yaoyu\\exam\\秦洲試題單選.docx");
file = new File("E:\\yaoyu\\exam\\醫療單選整合后帶答案 (自動保存的).docx");
XWPFDocument doc = null;
POIXMLTextExtractor extractor = null;
try {
doc = new XWPFDocument(new FileInputStream(file));
extractor = new XWPFWordExtractor(doc);
String content = extractor.getText();
System.out.println(content);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (doc != null) {
doc.close();
}
if (extractor != null) {
extractor.close();
}
} catch (IOException e) {
}
}
}
}