Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。












想改善这个问题吗?更新问题,以使为on-topic

6年前关闭。



Improve this question





有图书馆可以做到这一点吗?我看过docx4j,但是(我认为)它没有计算docx文件字数的功能。

最佳答案

最好的Java库是Apache POI

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;


public class NewDocReader {

public static void main(String args[]) throws FileNotFoundException, IOException
{


File docFile=new File("c:\\multi\\multi.docx");   // file object was created
FileInputStream finStream=new FileInputStream(docFile.getAbsolutePath()); // file input stream with docFile
HWPFDocument doc=new HWPFDocument(finStream);// throws IOException and need to import org.apache.poi.hwpf.HWPFDocument;
WordExtractor wordExtract=new WordExtractor(doc); // import  org.apache.poi.hwpf.extractor.WordExtractor
String [] dataArray =wordExtract.getParagraphText();
// dataArray stores the each line from the document

int pozicijaBlankoMesta;
for(int i=0;i<dataArray.length;i++)
{  .............
}


}

10-08 16:13