JAVA利用poi获取world文件内容

  本文主要简单介绍了利用poi包,读取world文件内容。

  这个依然存在版本的问题,只能读取doc结尾的老版本文件。

  话不多说,上代码:

 1 import java.io.File;
 2 import java.io.FileInputStream;
 3 
 4 import org.apache.poi.hwpf.HWPFDocument;
 5 import org.apache.poi.hwpf.usermodel.Range;
 6 
 7 
 8 public class testdoc {
 9     /**
10      * 读取doc文件内容
11      * @param file 想要读取的文件对象
12      * @return 返回文件内容
13      */
14     public static String doc2String(File file){
15         String result = "";
16         try{
17             FileInputStream fis = new FileInputStream(file);
18             HWPFDocument doc = new HWPFDocument(fis);
19             Range rang = doc.getRange();
20             result += rang.text();
21             fis.close();
22         }catch(Exception e){
23             e.printStackTrace();
24         }
25         return result;
26     }
27     public static void main(String[] args){
28         File file = new File("D:/luceneData/test6.doc");
29         System.out.println(doc2String(file));
30     }
31 }

读取文件

保存结果

读取结果

 

需要的jar包

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值