Android 打开失败:EBUSY(设备或资源繁忙)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11539657/
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-20 07:58:33  来源:igfitidea点击:

open failed: EBUSY (Device or resource busy)

androidinputstreamunzip

提问by Informatic0re

I have a strange error in my App.

我的应用程序中有一个奇怪的错误。

In my app it is possible to download a zipFile, read the content as what it is and also delete it. Its doesn't matter what exactly it is.

在我的应用程序中,可以下载一个 zipFile,按原样阅读内容并删除它。它到底是什么并不重要。

Problem: Only on the Motorola Xoom (version 4.0.4) I can download the file, unzip it, I can read the data and I can delete everything. But if I try to Download the file again and while it unzip the file and copy the files to SD-Card it crashes with the error EBUSY (Device or resource busy).

问题:只有在摩托罗拉 Xoom(4.0.4 版)上我才能下载文件、解压、读取数据和删除所有内容。但是,如果我尝试再次下载文件,并且在解压缩文件并将文件复制到 SD 卡时,它会崩溃并显示错误 EBUSY(设备或资源繁忙)。

  1. Why is it working only the first time?
  2. What means that error?
  3. Why i get this error only on the Xoom?
  1. 为什么它只在第一次工作?
  2. 这个错误是什么意思?
  3. 为什么我只在 Xoom 上出现这个错误?

I can't find any solution for that. On all other devices it works fine, no errors or problems.

我找不到任何解决方案。在所有其他设备上它工作正常,没有错误或问题。

LogCat:

日志猫:

07-18 12:27:46.774: E/PrepareMagTask(10057): IOException
07-18 12:27:46.774: E/PrepareMagTask(10057): java.io.FileNotFoundException: /mnt/sdcard/Android/data/com.xxxxxx.android/files/content/23760/emag.db: open failed: EBUSY (Device or resource busy)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at libcore.io.IoBridge.open(IoBridge.java:406)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at com.xxxxx.android.util.io.ZipHelper.uncompressEntry(ZipHelper.java:35)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at com.xxxxx.android.task.PrepareMagTask.doInBackground(PrepareMagTask.java:271)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at com.xxxxx.android.task.PrepareMagTask.doInBackground(PrepareMagTask.java:1)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at android.os.AsyncTask.call(AsyncTask.java:264)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at java.lang.Thread.run(Thread.java:856)
07-18 12:27:46.774: E/PrepareMagTask(10057): Caused by: libcore.io.ErrnoException: open failed: EBUSY (Device or resource busy)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at libcore.io.Posix.open(Native Method)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
07-18 12:27:46.774: E/PrepareMagTask(10057):    at libcore.io.IoBridge.open(IoBridge.java:390)
07-18 12:27:46.774: E/PrepareMagTask(10057):    ... 11 more

It crashes at line 35 in my ZipHelper class:

它在我的 ZipHelper 类中的第 35 行崩溃:

FileHelper.copy(zipFile.getInputStream(entry), new FileOutputStream(outputFile), modify);

getInputStream(entry) ... and I really dont know why?

getInputStream(entry) ...我真的不知道为什么?

Is there a method to wait for the device or recourse, when it is busy? This is happened every time I try to unzip the file, the app tries it 5 time (Downloading -> Unzip) and it crashes every time.

有没有办法在设备或资源繁忙时等待它?每次我尝试解压缩文件时都会发生这种情况,应用程序尝试了 5 次(下载 - > 解压缩)并且每次都崩溃。

EDIT: We found out, its not only the Xoom. We also have the error with the Asus Transformer with the version 4.0.4

编辑:我们发现,它不仅是 Xoom。我们也有版本 4.0.4 的 Asus Transformer 的错误

回答by Informatic0re

I have a big Answer!! The Problem comes from the Android System or/and the FAT32 system. I can not explain how the system gets the error, it has something to do with deleting files and the FAT32 System.

我有一个很大的答案!!问题来自Android系统或/和FAT32系统。我无法解释系统是如何出现错误的,它与删除文件和 FAT32 系统有关。

But the solution is really easy: Before you delete a Directory or File: rename it!

但解决方案真的很简单:在删除目录或文件之前:重命名它!

Code to rename:

重命名代码:

final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
file.renameTo(to);
to.delete();

That's it, if you rename the folder or file before you delete it, there is no chance for the system to try to open an existing file again or an open file which you want to save again (or something like this).

就是这样,如果您在删除之前重命名文件夹或文件,系统就没有机会再次尝试打开现有文件或您想再次保存的打开文件(或类似的东西)。

回答by caopeng

This issue may be cause by

这个问题可能是由于

  • two or more process reference the same file

  • file was deleted,but the reference not be killed

  • 两个或多个进程引用同一个文件

  • 文件被删除,但引用不会被杀死

However,deleted it,only one reference was killed,or one or moreprocess reference this file also

然而,删除它,只有一个引用被杀死,或者一个或多个进程也引用了这个文件

you can step by step:

你可以一步一步:

before you delete the file you should

在你删除文件之前,你应该

  • adb shell lsof | grep "com.xxxxxx.android"
  • adb shell lsof | grep "com.xxxxxx.android"

The file you have been opened,and which process reference the file which you opened. also,this command ,show us the process id

您已打开的文件,以及哪个进程引用了您打开的文件。此外,此命令还向我们显示进程 ID

than,

比,

  • adb shell ls -al /proc/%d/fd
  • adb shell ls -al /proc/%d/fd

Surprise waiting for you, O(∩_∩)O

惊喜等着你,O(∩_∩)O

good luck!

祝你好运!

回答by Jay Bobzin

It seems to be a lingering filesystem lock. I fixed it without touching my code, I think it was by unplugging my USB cable and re-plugging it in.

它似乎是一个挥之不去的文件系统锁。我在没有触及我的代码的情况下修复了它,我认为是通过拔下 USB 电缆并重新插入它。

回答by Laurie Clark

Was getting the exact same error, tried unplugging, restarting eclipse etc but nothing was working. Finally had to reboot phone and all fell back into place ;)

得到完全相同的错误,尝试拔掉电源,重新启动 eclipse 等,但没有任何效果。最后不得不重启手机,一切都恢复原状;)

Thanks for putting me on the right route !!

谢谢你让我走上正确的道路!!

回答by Venkatesh

I noticed this error in Sony Xperia when file in the directory not closed after writing some content in to it and I am trying to access(modify/delete) the directory.

当目录中的文件在写入一些内容后未关闭时,我在 Sony Xperia 中注意到此错误,并且我正在尝试访问(修改/删除)该目录。

Make sure to close the file properly. Make sure no program is accessing your files. Then you wont come across this error.

确保正确关闭文件。确保没有程序正在访问您的文件。那么你就不会遇到这个错误。

If you are unsure that any program might be accessing your directory, be sure to delete(/close) all the files in the directory before deleting the directory.

如果您不确定任何程序可能正在访问您的目录,请确保在删除目录之前删除(/关闭)目录中的所有文件。

adb reboot is one option to close opened files. But that is not a good option to do so.

adb reboot 是关闭打开文件的一种选择。但这不是一个好的选择。

回答by ShellDude

I understand that this is an old issue, and was originally reported specific to a XOOM, but if the OP had an open FileOutputStream that was not properly closed, i.e. via a Finally block, then that is likely what is causing the resource to be held when attempting to reference it later... even if the physical file was actually deleted.

我知道这是一个老问题,最初是针对 XOOM 报告的,但是如果 OP 有一个未正确关闭的打开 FileOutputStream,即通过 finally 块,那么这可能是导致资源被保留的原因稍后尝试引用它时...即使实际删除了物理文件。

回答by farrellw

The message rm: could not remove directory (code EBUSY), means that some app or process is using the directory.

消息rm: could not remove directory (code EBUSY), 表示某些应用程序或进程正在使用该目录。

For me, this usually means AndroidStudio, Webstorm, or another IDE is open. If you have an IDE open, closing it can free up the process to remove the folder. After closing, just run the removal again.

对我来说,这通常意味着 AndroidStudio、Webstorm 或其他 IDE 已打开。如果您打开了一个 IDE,关闭它可以释放删除文件夹的过程。关闭后,只需再次运行删除。