I'm studying these days java io Flowing things , A netizen asked a question after seeing the blog , That means his doc Why is the document dead or alive in the way I say it is messy .

At first I thought it was his method , The results of their own after trying to find and his results are also garbled .

So I searched the Internet for a while before I found out doc Documentation and excel You can't use ordinary ones io Stream method to read , It also needs to be used poi, So after a few attempts , Finally, I read this in the correct encoding format doc file .

Found in the process of online search doc and docx The method of reading is different , So I learned it by the way docx Simple reading of files .

One , Guide Package :
doc File reading , Import required poi-scratchpad Of jar Packages and dependent packages :

docx File read , Import required poi-ooxml Of jar Packages and dependent packages :

I use it maven Build project , The dependent packages are imported automatically ,maven The guide package is configured as follows :
<dependency> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <version>3.8</version> </dependency>
<dependency> <groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId> <version>3.8</version> </dependency>
Two , Read the code of the file :
1,doc Simple example of file reading :
public static void readAndWriterTest3() throws IOException { File file = new
File("C:\\Users\\tuzongxun123\\Desktop\\aa.doc"); String str = ""; try {
FileInputStream fis = new FileInputStream(file); HWPFDocument doc = new
HWPFDocument(fis); String doc1 = doc.getDocumentText();
System.out.println(doc1); StringBuilder doc2 = doc.getText();
System.out.println(doc2); Range rang = doc.getRange(); String doc3 =
rang.text(); System.out.println(doc3); fis.close(); } catch (Exception e) {
e.printStackTrace(); } }
2,docx Simple example of file reading :
public static void readAndWriterTest4() throws IOException { File file = new
File("C:\\Users\\tuzongxun123\\Desktop\\aa.docx"); String str = ""; try {
FileInputStream fis = new FileInputStream(file); XWPFDocument xdoc = new
XWPFDocument(fis); XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
String doc1 = extractor.getText(); System.out.println(doc1); fis.close(); }
catch (Exception e) { e.printStackTrace(); } }
//20171218 modify
I didn't do it at work word, This blog is only done on the spur of the moment , So it's very simple .
Recently, some friends came to me to ask me some questions , Several of them are asking what are the dependent packages , To avoid answering this question again and again , Will rely on the package screenshot :

©2019-2020 Toolsou All rights reserved,
The 11th Blue Bridge Cup python The real topic of the University Group National Games JavaSwing To achieve a simple Lianliankan games 【Spring Source code analysis 】42-@Conditional Detailed explanation element-ui Step on pit record 2019PHP Interview questions ( Continuously updated )PHPJava Misunderstanding —— Method overloading is a manifestation of polymorphism ? First issue 500 100 million , Set up a new Department , What is Tencent going to do ? Google chrome The browser can't open the web page , But what if other browsers can open it ? Regression of dependent variable order categories (R language )【Golang Basic series 10 】Go language On conditional sentences if