Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassNotFoundException: org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream on using HSSFWorkbook

Tags:

java

excel

I'm trying to implement reading from .xls file. I have the following code:

FileInputStream file = null;
    Workbook workbook = null;
    try {
        file = new FileInputStream(System.getProperty("user.home") + "/Downloads/" + fileName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    if (fileName.endsWith(".xls")) {
        try {
            **workbook = new HSSFWorkbook(file);**
        } catch (IOException e) {
            e.printStackTrace();
        }

This marked code line crashes.

I imported in pom.xml:

<dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>5.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.2.0</version>
    </dependency>

but I got the error: Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream

I would appreciate help on this. Thanks.

like image 472
libero Avatar asked Dec 02 '25 04:12

libero


1 Answers

It worked for me

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.11.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>5.2.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.2.2</version>
    </dependency>
like image 160
Luiz Henrique Serafim Avatar answered Dec 03 '25 17:12

Luiz Henrique Serafim