poi获取word文本支持doc和docx后缀。
/**
* 获取文本内容
* @param filePath
* @return
* @throws Exception
*/
public static String getDocAllText(String filePath) {
FileInputStream fis = null;
try{
fis = new FileInputStream(filePath);
WordExtractor wordExtractor = new WordExtractor(fis);
return wordExtractor.getText();
}catch (Exception e){
throw new RuntimeException(e);
}finally {
if(fis != null){
try{
fis.close();
}catch (Exception e){
}
}
}
}
网友评论