Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol 'IOUtils'

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.

like image 994
Harikrishnan Avatar asked Jul 04 '14 16:07

Harikrishnan


People also ask

What is IOUtils?

IOUtils provide utility methods for reading, writing and copying files. The methods work with InputStream, OutputStream, Reader and Writer.


2 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 :)

like image 79
Ivo Stoyanov Avatar answered Oct 05 '22 19:10

Ivo Stoyanov


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

like image 27
Harikrishnan Avatar answered Oct 05 '22 19:10

Harikrishnan