/**
* 读取doc文件内容
*
* @param file 想要读取的文件对象
* @return 返回文件内容
*/
public static String doc2String(File file)
{
String result = “”;
try
{
FileInputStream fis = new FileInputStream(file);
HWPFDocument doc = new HWPFDocument(fis);
Range rang = doc.getRange();
result += rang.text();
fis.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return result;
}
java中将word转String
本文介绍了一种使用Java编程语言从DOC文件中提取文本的方法。通过利用Apache POI库中的HWPFDocument类,可以轻松地读取Word文档并获取其全部内容。

被折叠的 条评论
为什么被折叠?



