java openfile busy_android java.io.IOException: open failed: EBUSY (Device or resource busy)
今天遇到一個(gè)奇怪的問(wèn)題,
測(cè)試在程序的下載界面,下載一個(gè)文件第一次下載成功,刪除后再下載結(jié)果下載報(bào)錯(cuò),
程序:file.createNewFile();
報(bào)錯(cuò):java.io.IOException: open failed: EBUSY (Device or resource busy)
程序:RandomAccessFile randomAccessFile = new RandomAccessFile(localfile, "rwd");
報(bào)錯(cuò):java.io.FileNotFoundException: open failed: EBUSY (Device or resource busy)
at libcore.io.IoBridge.open
......一啪啦
這些手機(jī)都沒(méi)問(wèn)題,就只有華為的一款有這個(gè)問(wèn)題,在網(wǎng)上查了,說(shuō)的是FAT32 system,
這是這個(gè)測(cè)試機(jī)的系統(tǒng),具體的不知道跟這個(gè)到底有沒(méi)關(guān)系,反正根據(jù)網(wǎng)上一段話說(shuō)的是把要?jiǎng)h除的文件改名然后再刪除,下次下載時(shí),就算沒(méi)刪掉,文件名也改了,所以第二次就能下載了。
刪除文件代碼:
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();
}
解決問(wèn)題參考網(wǎng)址:http://stackoverflow.com/questions/11539657/open-failed-ebusy-device-or-resource-busy
總結(jié)
以上是生活随笔為你收集整理的java openfile busy_android java.io.IOException: open failed: EBUSY (Device or resource busy)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 冰雪之城简单难度,四个人平均多少战力能过
- 下一篇: 亏赚我会采纳的谢谢