/**
* 段落读取
*
* @param in 文件输入流
* @throws IOException IO流异常
*/
public void read(FileInputStream in) throws IOException {
WordExtractor we = new WordExtractor(in);
String[] strArray = we.getParagraphText();//按段落读取word
for (; i < strArray.length; i++) {
System.out.print("第" + (i + 1) + "段 is " + strArray[i]);
}
}
}
/**
* 读取word全部内容
* @param in
*/
public void readWord(FileInputStream in) {
try {
//读取word文档
HWPFDocument doc = new HWPFDocument(in);
Range rang = doc.getRange();//
int num = rang.numParagraphs();//获取段
String text = rang.text();//获取文本内容(文件稍微大点就无法读取)
System.out.println("该文档共" + num + "段");//空行也算一段
System.out.println("word content is" + text);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}