gpt4 book ai didi

java - 将 Word 文档读入处理时出错

转载 作者:行者123 更新时间:2023-12-01 17:54:26 32 4
gpt4 key购买 nike

我正在尝试从Word文件中读取文本数据,找到了以下Java答案的链接

How read Doc or Docx file in java?

我决定编写一些代码。

import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;

String s = "C:\\Users\\admin\\Desktop\\doc.doc";

String []doc = null;


String [] func(String Loc){
WordExtractor extractor = null;
String s = "sketch_200318a\\";
String [] fileData = null;
File file = null;

try{

file = new File(Loc);
FileInputStream fis = new FileInputStream(file.getAbsolutePath());

HWPFDocument document = new HWPFDocument(fis);
extractor = new WordExtractor(document);

fileData = extractor.getParagraphText();

for (int i = 0; i < fileData.length; i++){

if (fileData[i] != null)System.out.println(fileData[i]);

}}
catch (Exception exep){
//exep.printStackTrace();
}
return fileData;
};

void setup(){
size(400,400);
doc = func(s);
};

void draw(){
background(51);

fill(255);
for(int i=0;i<doc.length;i++){
text(doc[i],10,10+10*i);
}

};

但是此代码不起作用

并产生以下错误

java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils

at org.apache.poi.poifs.property.RootProperty.setSize(RootProperty.java:59)
at org.apache.poi.poifs.property.DirectoryProperty.<init>(DirectoryProperty.java:52)
at org.apache.poi.poifs.property.RootProperty.<init>(RootProperty.java:31)
at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:58)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:102)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:274)
at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:129)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:165)
at sketch_200318a.func(sketch_200318a.java:272)
at sketch_200318a.setup(sketch_200318a.java:290)
at processing.core.PApplet.handleDraw(PApplet.java:2432)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.util.ArithmeticUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more

我是否可以理解我在某个地方缺少一些依赖项或库?

最佳答案

是的,它缺少一个库,poi 包含一个 lib 文件夹,需要将其添加到项目代码文件夹中。

关于java - 将 Word 文档读入处理时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60745268/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com