java 操作word 使用POI3.7
public static void readWord2003(String filename) { InputStream inputStream = null; WordExtractor wordExtractor = null; String word = null; try { inputStream = new FileInputStream(filename); wordExtractor = new WordExtractor(inputStream); word = wordExtractor.getText(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (null != inputStream) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } System.out.println(word); } public static void readWord2007(String filename) { OPCPackage opcPackage = null; XWPFWordExtractor xwpfWordExtractor = null; String word = null; try { opcPackage = POIXMLDocument.openPackage(filename); xwpfWordExtractor = new XWPFWordExtractor(opcPackage); word = xwpfWordExtractor.getText(); } catch (IOException e) { e.printStackTrace(); } catch (XmlException e) { e.printStackTrace(); } catch (OpenXML4JException e) { e.printStackTrace(); } System.out.println(word); }