Android删除文件后重新创建时偶尔出现 open failed: EBUSY (Device or resource busy)错误,该错误是Android系统的一个bug,大概的意思类似于windows的“改文件正在被使用”。产生这个错误的原因是Android在删除文件后没有及时释放文件锁,导致文件在重新创建时仍然处于被某一进程占用的状态。解决的方法是:在删除文件之前对该文件进行重命名,这样可以保证在删除文件时系统持有的文件锁是重命名之后的文件锁。代码可以这样写:

final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
file.renameTo(to);
to.delete();
最后再重新创建文件就可以了。

Android文件操作报open failed: EBUSY (Device or resource busy)的更多相关文章

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

    今天遇到一个奇怪的问题, 测试在程序的下载界面,下载一个文件第一次下载成功,删除后再下载结果下载报错, 程序:file.createNewFile(); 报错:java.io.IOException: ...

  2. read()、write()返回 Input/output error, Device or resource busy解决

    遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...

  3. android 文件操作类简易总结

    android 文件操作类(参考链接) http://www.cnblogs.com/menlsh/archive/2013/04/02/2997084.html package com.androi ...

  4. Linux下rm -rf删除文件夹报错_ Device or resource busy

    1.错误信息 rm: cannot remove `speechd-centos_6.2-prtl-pred-mf34/modules/t2p/py/third/g2p/.nfs00000000039 ...

  5. Docker - 解决在容器内删除和主机映射的目录而报错 rm: cannot remove 'webapps': Device or resource busy 的问题

    问题背景 docker run -d --name tomcat7 -v /usr/local/tomcat/webapps:/usr/local/tomcat/webapps tomcat:7 使用 ...

  6. mount: mounting proc on /proc failed: Device or resource busy

    /********************************************************************** * mount: mounting proc on /p ...

  7. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

    在 mkfs.ext4 /dev/sda2 格式化硬盘空间时,可能出现这种错误. had this situation at office where I was told to re-partiti ...

  8. docker中执行sed: can't move '/etc/resolv.conf73UqmG' to '/etc/resolv.conf': Device or resource busy错误的处理原因及方式

    错误现象 在docker容器中想要修改/etc/resolv.conf中的namesever,使用sed命令进行执行时遇到错误: / # sed -i 's/192.168.1.1/192.168.1 ...

  9. Docker之rm: Device or resource busy

    docker 容器里 rm -rf /data 提示: rm: cannot remove ‘/data’: Device or resource busy 原因: 在建立容器的时候做了相应目录的挂载 ...

随机推荐

  1. [国家集训队2010]小Z的袜子

    ★★★   输入文件:hose.in   输出文件:hose.out   简单对比 时间限制:1 s   内存限制:512 MB [题目描述] 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜 ...

  2. Mybatis错误——Could not find parameter map java.util.Map

    错误信息 org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map java.util.Ma ...

  3. pga_aggregate_target, sga_target, memory_target

    对于这三个参数有一些了解,但是又有一些疑惑. pga_aggregate_target 最初的了解: 这个参数控制着PGA的大小,如果work_area_policy 设置成auto,则oracle采 ...

  4. NetCore发布WebApi项目到IIS服务器中

    1.确保已在机器上安装Net Core Runtime,,下载地址: https://dotnet.microsoft.com/download 2.点击WebApi项目右键->发布,选择IIS ...

  5. golang中channels的本质详解,经典!

    原文:https://www.goinggo.net/2014/02/the-nature-of-channels-in-go.html The Nature Of Channels In Go 这篇 ...

  6. ubuntu各文件夹简介 [转载]

    原文地址:ubuntu各文件夹简介作者:SuperZhy ubuntu各文件夹简介 /bin 二进制可执行命令/dev 设备文件(硬盘/光驱等)/etc 系统管理和配置文件/etc/rc.d 启动的配 ...

  7. QT如何修改字符编码格式

    编辑-Select Encoding,然后在弹出窗口中修改字符编码.                      

  8. C#之反射(PropertyInfo类)

    1.引入命名空间:System.Reflection:程序集:mscorlib(在mscorlib.dll中) 2.示例代码(主要是getType().setValue().getValue()方法) ...

  9. 【转】 vsftp上传文件出现553 Could not create file解决方法

    因工作需要,需要搭建一个ftp服务器,我使用ubuntu 10.04操作系统,下载vsftpdy源代码, 进行了编译,安装,然后按照INSTALL文件,创建了用户等操作.    因为时间比较紧,我采用 ...

  10. tomcat连接mysql的3个问题解决

    转载请标明出处: 本文出自:[ouyida3的博客] 1.BasicDataSourceFactory Caused by: java.lang.ClassNotFoundException: org ...