Home » Android » java – Cannot resolve symbol 'IOUtils'

java – Cannot resolve symbol 'IOUtils'

Posted by: admin April 23, 2020 Leave a comment


I have used the following code to create a temporary file in my android app:

public File streamToFile (InputStream in) throws IOException {
    File tempFile = File.createTempFile("sample", ".tmp");
    FileOutputStream out = new FileOutputStream(tempFile);
    IOUtils.copy(in, out);
    return tempFile;

Now the problem is Cannot resolve symbol 'IOUtils'. I did a little bit of googling and discovered that for using IOUtils I need to download and include a jar file. I downloaded the jar file from here(commons-io-2.4-bin.zip). I added the jar named commons-io-2.4.jar from the zip to my bundle and when I tried to import it using:

import org.apache.commons.io.IOUtils;

It is showing error Cannot resolve symbol 'io'. So I tried to import it like:

import org.apache.commons.*

But still I am getting the error Cannot resolve symbol 'IOUtils'.

Question 1 : Why am I getting this error? How to resolve it?

Question 2 : Is there any way to create a temp file from an InputStream without using an external library? Or is this the most efficient way to do that? I am using android studio.

How to&Answers:

For Android Studio:

  1. File -> Project Structure… -> Dependencies
  2. Click ‘+’ in the upper right corner and select “Library dependency”
  3. In the search field type: “org.apache.commons.io” and click Search
  4. Select “org.apache.directory.studio:org.apache.commons.io:

Happy coding 🙂


Right clicking on the commons-io-2.4.jar file in project navigator and clicking ‘Add to project’ solved the issue.


For those who encountered this while working on a Netbeans Java project. What I did is I downloaded the Binaries Zip of IO here

Commons IO Util Jar Download Here

Then Right clicked on my Project>Properties>

On the Categories Pane, Click Libraries

Then Click Add Jar/Folder

Locate the jar file/folder of the extracted IO Util that was downloaded.

Then click Ok. That fixed mine. 🙂