Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copyInputStreamToFile method does not exist

I'm trying to use the copyInput method in my code, but seems like Intellij told me that the method does not exist

FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile);

I'm using the code from here

http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

But it seems like the method exist here

https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/FileUtils.html

I'm using maven, I tried with 2.0, 2.1, 2.4 without luck

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

Java 1.8

Here is the error message

Error:(201, 22) java: cannot find symbol symbol: method copyInputStreamToFile(java.io.InputStream,java.io.File) location: class org.apache.commons.io.FileUtils

enter image description here

like image 636
msiles Avatar asked May 24 '16 22:05

msiles


2 Answers

You probably have another (older) org.apache.commons.io.FileUtils on your classpath, which would explain the issues you're having. Most likely one of your dependencies has an old org.apache.commons:commons-io artifact on the classpath. Due to the groupId difference, Maven considers them different artifacts and puts both on the classpath.

If that is what's really happening, you can explicitly forbid maven from including this transitive dependency by adding an exclusion to the dependency that references the old commons-io (even if it depends on it transitively):

<dependency>
  <groupId>offending.artifact.groupId</groupId>
  <artifactId>offending.artifact.artifactId</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-io</artifactId>
    </exclusion>
  </exclusions>
</dependency>
like image 65
Anton Koscejev Avatar answered Sep 25 '22 17:09

Anton Koscejev


I was able to see the wrong version using the menu options "To find the offending class in IntelliJ IDEA: Menu > Navigate > Class > type FileUtils", there were like 4 FileUtils,

I imported the correct version on the jar file and it fix the problem, Thanks @Anton.

like image 41
msiles Avatar answered Sep 23 '22 17:09

msiles