Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method toByteArray(InputStream) is undefined for the type IOUtils

I am working on spring boot.I have a method to return a file using byte array.while i am trying to return byteArray I got this error.my code is given below-

@GetMapping(
      value = "/get-file",
      produces = MediaType.APPLICATION_OCTET_STREAM_VALUE
    )
    public @ResponseBody byte[] getFile() throws IOException {

        InputStream in = getClass()
          .getResourceAsStream("/com/baeldung/produceimage/data.txt");
        return IOUtils.toByteArray(in);
    }
like image 421
user2893186 Avatar asked May 27 '18 05:05

user2893186


1 Answers

Very likely, you have imported the wrong IOUtils from tomcat (import org.apache.tomcat.util.http.fileupload.IOUtils;)

Add Apache Commons IO dependency

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

and use the following import

import org.apache.commons.io.IOUtils;
like image 83
Ranjith Avatar answered Sep 29 '22 16:09

Ranjith