码迷,mamicode.com
首页 > 移动开发 > 详细

Android App更新时Log显示如下错误信息

时间:2020-10-16 10:47:37      阅读:39      评论:0      收藏:0      [点我收藏+]

标签:mamicode   for   crash   清除   目录结构   libc   library   more   清理   

Logger写*.log文件时 Console Log:

W/System.err: java.io.IOException: open failed: ENOENT (No such file or directory)
W/System.err:     at java.io.File.createNewFile(File.java:939)
W/System.err:     at com.mmednet.library.log.Logger$1.runInBackground(Logger.java:191)
W/System.err:     at com.mmednet.library.log.Logger$1.runInBackground(Logger.java:174)
W/System.err:     at com.mmednet.library.log.RunTask.run(RunTask.java:76)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
W/System.err:     at libcore.io.Posix.open(Native Method)
W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
W/System.err:     at java.io.File.createNewFile(File.java:932)
W/System.err: ... 6 more

出现原因:
清除缓存功能将文件目录清除掉,但是Logger工具类仍然往目录中写文件,就出现了 ENOENT (No such file or directory) 的异常,所以在删除缓存时,只删除缓存文件,不破坏目录结构:

/**
 * 只删除文件,不删除文件夹
 */
private static boolean deleteDir(File dir) {
    if (dir == null) {
        return false;
    }
    if (dir.isDirectory()) {
        String[] children = dir.list();
        int len = children.length;
        if (len == 0) {
            return true;
        }
        for (int i = 0; i < len; i++) {
            //无论File是目录还是文件,file.isDirectory() 、file.isFile() 都会返回false
            File file = new File(children[i]);
            Logger.e("new File(a) 类型: " + file.getName() + " " + file.isDirectory() + "  " + file.isFile());
            File child = new File(dir, children[i]);
            Logger.e("new File(a, b) 类型: " + file.getName() + " " + child.isDirectory() + "  " + child.isFile());
            boolean success;
            if (child.isDirectory()) {
                if (child.list().length == 0) {
                    return true;
                }
                success = deleteDir(child);
            } else {
                success = child.delete();
            }
            if (!success) {
                return false;
            }
            Logger.w(TAG, "dir: " + dir.getName() + " child : " + child.getName() + " success : " + success);
            if (i == len - 1) {
                return true;
            }
        }
    }
    return dir.isDirectory();
}

目录结构为:

cache

crash -> empty

info -> *.log files

1-》2,删除info下所有的文件;3 crash(empty).length==0,return true,标识cache文件夹清理完成

技术图片

Android App更新时Log显示如下错误信息

标签:mamicode   for   crash   清除   目录结构   libc   library   more   清理   

原文地址:https://www.cnblogs.com/jooy/p/13821234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!