public void Traverse(File dir) throws IOException {
    if (dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; children != null && i < children.length; i++) {
           Traverse(new File(dir, children[i]));
        }
    }

    if (dir.isFile()) {
        // do whatever you want
    }
}

参考资料:
[1]什么是尾递归?http://en.wikipedia.org/wiki/Tail_recursion


小朋友
395 声望11 粉丝