|
Вы можете использовать следующий код, чтобы реализовать свой собственный файл-браузер на Яве. VisitAllDirsAndFiles метода проходит все папки и файлы в заданной директории. VisitAllDirsAndFiles метода делает то же, только для каталогов. Process () метод должен быть определен на основе Вашей потребности ..
// Process all files and directories under dir
public static void visitAllDirsAndFiles(File dir) {
// You can do whatever you want with this directory
// E.g. printing its name to the console
process(dir);
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
visitAllDirsAndFiles(new File(dir, children[i]));
}
}
}
// Process only directories under dir
public static void visitAllDirs(File dir) {
if (dir.isDirectory()) {
// You can do whatever you want with this directory
// E.g. printing its name to the console
process(dir);
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
visitAllDirs(new File(dir, children[i]));
}
}
}
|
|
Комментарии