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包

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM