Cannot resolve symbol 'IOUtils'

Issue

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");
    tempFile.deleteOnExit();
    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.

Solution

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

Answered By – Harikrishnan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published