android.os.FileUtils#listFilesOrEmpty ( )源码实例Demo

下面列出了android.os.FileUtils#listFilesOrEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: RescueParty.java
private static int[] getAllUserIds() {
    int[] userIds = { UserHandle.USER_SYSTEM };
    try {
        for (File file : FileUtils.listFilesOrEmpty(Environment.getDataSystemDeDirectory())) {
            try {
                final int userId = Integer.parseInt(file.getName());
                if (userId != UserHandle.USER_SYSTEM) {
                    userIds = ArrayUtils.appendInt(userIds, userId);
                }
            } catch (NumberFormatException ignored) {
            }
        }
    } catch (Throwable t) {
        Slog.w(TAG, "Trouble discovering users", t);
    }
    return userIds;
}
 
源代码2 项目: AndroidComponentPlugin   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
源代码3 项目: AndroidComponentPlugin   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
源代码4 项目: AndroidComponentPlugin   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
源代码5 项目: AndroidComponentPlugin   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
源代码6 项目: AndroidComponentPlugin   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
源代码7 项目: AndroidComponentPlugin   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
源代码8 项目: AndroidComponentPlugin   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}
 
源代码9 项目: android_9.0.0_r45   文件: ContextImpl.java
/**
 * Try our best to migrate all files from source to target that match
 * requested prefix.
 *
 * @return the number of files moved, or -1 if there was trouble.
 */
private static int moveFiles(File sourceDir, File targetDir, final String prefix) {
    final File[] sourceFiles = FileUtils.listFilesOrEmpty(sourceDir, new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(prefix);
        }
    });

    int res = 0;
    for (File sourceFile : sourceFiles) {
        final File targetFile = new File(targetDir, sourceFile.getName());
        Log.d(TAG, "Migrating " + sourceFile + " to " + targetFile);
        try {
            FileUtils.copyFileOrThrow(sourceFile, targetFile);
            FileUtils.copyPermissions(sourceFile, targetFile);
            if (!sourceFile.delete()) {
                throw new IOException("Failed to clean up " + sourceFile);
            }
            if (res != -1) {
                res++;
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to migrate " + sourceFile + ": " + e);
            res = -1;
        }
    }
    return res;
}