---
title: "使用POI抽取Word内容"
author: "longforfreedom"
date: "2009-12-03T20:33:14Z"
tags: []
slug: "poi-word"
draft: false
lastmod: "2009-12-03T20:33:14Z"
id: 540403
url: "https://migle.iteye.com/blog/540403"
---

使用POI3.5抽取Word内容只需要一句

 

```
	/**
	 * 使用<a href="http://poi.apache.org/">POI</a>抽取MS office 2003 word格式的文件内容
	 * @param file
	 *            MS Word2003 格式的{@link File}实例
	 * @return 文件内容的{@link String}
	 * @throws IOException
	 * @throws FileNotFoundException
	 */
	public String getContents(File file) throws FileNotFoundException,
			IOException {
		WordExtractor wordExtractor = new WordExtractor(new FileInputStream(
				file));
		return wordExtractor.getTextFromPieces();
	}
```