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,
hive compress &&hdfs Merge small files I've been drinking soft water for three years ? What is the use of soft water and water softener 《 League of Heroes 》 Mobile game open public test : support iOS/Android Dual platform The situation of receiving and receiving multi-path VaR - Value at risk - Monte Carlo method - Pythonnumpy: The creation of multidimensional array uniapp Summary of page value transfer use C Language makes a very simple airplane game Docker Container data volume ,DockerfileJavaScript Medium Call and Apply