无法解析符号'IOUtils' [英] Cannot resolve symbol 'IOUtils'

查看:674
本文介绍了无法解析符号'IOUtils'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在我的Android应用程序中创建一个临时文件:

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;
}

现在问题是无法解析符号'IOUtils' 。我做了一些谷歌搜索,发现使用IOUtils我需要下载并包含一个jar文件。我从 此处 下载了jar文件( commons-io-2.4-bin.zip )。我将名为 commons-io-2.4.jar 的jar从zip添加到我的包中,当我尝试使用以下方法导入它时:

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;

显示错误无法解析符号'io'。所以我尝试导入它像:

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

import org.apache.commons.*

但我仍然收到错误无法解析符号'IOUtils'

问题1:为什么我收到此错误?如何解决?

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

问题2:有没有办法在不使用外部库的情况下从InputStream创建临时文件?或者这是最有效的方法吗?我正在使用android studio。

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.

推荐答案

右键单击 commons-io-2.4.jar 文件并单击添加到项目解决了问题。

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

这篇关于无法解析符号'IOUtils'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆