• 深层遍历一个目录下面的子目录子文件


    深层遍历---------dfs(递归)

    package test;
     
     
    import java.io.*;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.zip.InflaterInputStream;
     
    import javax.annotation.processing.FilerException;
     
    import privateclass.Filterby_Name;
    import privateclass.Filterby_hidden;
    import privateclass.Filterby_java;
    import privateclass.MyBufferedReader;
     
    public class Main {
     
        private static final String space_operator = " ";
        private static final double pi = Math.PI;
        private static final String LINE_SEPARATOR = System.getProperty("line.separator");
        public static void main(String[] args) throws Exception {
     
            File file = new File("d:\文档");
            listall(file,0);
             
        }
        public static void listall(File file,int deep) {
            System.out.println(getdeep(deep) + file.getName());
            deep++;
            for(File x : file.listFiles())
            {
                if(x.isDirectory())
                {
                    listall(x,deep);
                }
                else
                {
                    System.out.println(getdeep(deep) + x.getName());
                }
            }
             
        }
        public static String getdeep(int deep) {
            StringBuilder s = new StringBuilder();
            for(int i = 0; i < deep; i ++)
            {
                s.append("    ");
            }
            return s.toString();
        }
    }
    

      

  • 相关阅读:
    HutchTab
    configbody tcl tk
    initial class tcl tk
    ::dcss
    StatusBar
    read url c#
    new tab addin
    extraDevice
    Android平台开发WIFI function portingWIFI功能移植
    如何设置Android系统中的BT2.1 device到SSP的DEBUG模式
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11815867.html
Copyright © 2020-2023  润新知