Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.io.FilenameFilter;

import java.util.Map;

public class Main {
    public static void traverseFolder(Map<String, File> fileMap, File rootFolder, File folderInCheck) {
        if (folderInCheck.isFile()) {
            int length = (int) rootFolder.getAbsolutePath().length();
            String pathKey = folderInCheck.getAbsolutePath().substring(length);
            fileMap.put(pathKey, folderInCheck);
            return;
        }

        String[] names = folderInCheck.list(new FilenameFilter() {
            // for filtering some files, such as ".xml"
            public boolean accept(File dir, String name) {
                return true;
            }
        });

        if (names == null || names.length == 0) {
            return;
        }

        File[] files = folderInCheck.listFiles();
        if (files == null || files.length == 0) {
            return;
        }

        for (File child : files) {
            traverseFolder(fileMap, rootFolder, child);
        }
    }
}