JAVA use poi get world file contents

  This paper introduces the use of poi package, read the world file contents.

  This version of the problem still exists, can only be read at the end of the old version of the file doc.

  Man of few words said on the code:

 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 }

Read the file

Save Results

Reading results

 

Required jar package

 

Reproduced in: https: //my.oschina.net/u/204616/blog/545242

Guess you like

Origin blog.csdn.net/weixin_34320159/article/details/91990031