Java 无法解析符号“IOUtils”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24578243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 13:09:31  来源:igfitidea点击:

Cannot resolve symbol 'IOUtils'

javaandroidapacheimportandroid-studio

提问by Harikrishnan

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

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

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.jarfrom the zip to my bundle and when I tried to import it using:

现在的问题是Cannot resolve symbol 'IOUtils'。我做了一点谷歌搜索,发现要使用 IOUtils,我需要下载并包含一个 jar 文件。我从这里下载了 jar 文件(commons-io-2.4-bin.zip)。我将commons-io-2.4.jarzip 中命名的 jar 添加到我的包中,当我尝试使用以下命令导入它时:

import org.apache.commons.io.IOUtils;

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

它显示错误Cannot resolve symbol 'io'。所以我试着像这样导入它:

import org.apache.commons.*

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

但我仍然收到错误Cannot resolve symbol 'IOUtils'

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

问题 1:为什么会出现此错误?如何解决?

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.

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

采纳答案by Harikrishnan

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

右键单击commons-io-2.4.jar项目导航器中的文件并单击“添加到项目”解决了该问题。

回答by Ivo Stoyanov

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:
  1. 文件 -> 项目结构... -> 依赖项
  2. 单击右上角的“+”并选择“库依赖项”
  3. 在搜索字段中键入:“org.apache.commons.io”并单击“搜索”
  4. 选择“org.apache.directory.studio:org.apache.commons.io:

Happy coding :)

快乐编码:)

回答by iamjoshua

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

对于在处理 Netbeans Java 项目时遇到此问题的人。我所做的是在这里下载了 IO 的 Binaries Zip

Commons IO Util Jar Download Here

Commons IO Util Jar 在这里下载

Then Right clicked on my Project>Properties>

然后右键单击我的项目>属性>



On the Categories Pane, Click Libraries

在类别窗格中,单击库



Then Click Add Jar/Folder

然后单击添加 Jar/文件夹



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

找到已下载的解压 IO Util 的 jar 文件/文件夹。



Then click Ok. That fixed mine. :)

然后单击确定。那个固定的我的。:)