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 code is given below-

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

        InputStream in = getClass()
        return IOUtils.toByteArray(in);


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

Add Apache Commons IO dependency


and use the following import


Leave a Reply

Your email address will not be published. Required fields are marked *