0

I am trying to read text data from word files, having found the following link to a java answer

How read Doc or Docx file in java?

I decided to code something up.

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); 
  }

};

This code however does not work

and produces the following error

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

Am I to understand that I am missing some dependencies somewhere or libraries?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Paul Goux
  • 35
  • 4

1 Answers1

0

Yes its a missing library, poi includes a lib folder which needs to be added to the project code folder.

Paul Goux
  • 35
  • 4