android java.io.IOException: open failed: EBUSY (Device or resource busy)

今天遇到一个奇怪的问题,

测试在程序的下载界面,下载一个文件第一次下载成功,删除后再下载结果下载报错,

程序:file.createNewFile();

报错:java.io.IOException: open failed: EBUSY (Device or resource busy)

程序:RandomAccessFile randomAccessFile = new RandomAccessFile(localfile, "rwd");

报错:java.io.FileNotFoundException: open failed: EBUSY (Device or resource busy)

at libcore.io.IoBridge.open

......一啪啦

这些手机都没问题,就只有华为的一款有这个问题,在网上查了,说的是FAT32 system,

resource

open

这是这个测试机的系统,具体的不知道跟这个到底有没关系,反正根据网上一段话说的是把要删除的文件改名然后再删除,下次下载时,就算没删掉,文件名也改了,所以第二次就能下载了。

删除文件代码:

   public void deleteSDCardFolder(File dir) {
       File to = new File(dir.getAbsolutePath() + System.currentTimeMillis());
       dir.renameTo(to);
       if (to.isDirectory()) {
           String[] children = to.list();
           for (int i = 0; i < children.length; i++) {
               File temp = new File(to, children[i]);
               if (temp.isDirectory()) {
                   deleteSDCardFolder(temp);
               } else {
                   boolean b = temp.delete();
                   if (b == false) {
                       Log.d("deleteSDCardFolder", "DELETE FAIL");
                   }
               }
           }
           to.delete();
       }

解决问题参考网址:http://stackoverflow.com/questions/11539657/open-failed-ebusy-device-or-resource-busy

原文地址:https://www.cnblogs.com/ldq2016/p/5581517.html