集册 Java实例教程 按文件名搜索目录

按文件名搜索目录

欢马劈雪     最近更新时间:2020-01-02 10:19:05

380
通过文件名搜索目录

/**
 * n o w j a   v  a . c o m - 时  代  Java 提 供 
**/

//package com.nowjava;


import java.io.File;


public class Main {

    public static void main(String[] argv) throws Exception {

        String path = "nowjava.com";

        String target = "nowjava.com";

        searchDir(path, target);

    }


    public static void searchDir(String path, String target) {

        File f = new File(path);

        if (path != null) {

            if (f.isDirectory()) {

                File[] fileArray = f.listFiles();

                if (fileArray != null) {

                    for (File file : fileArray) {

                        searchDir(file.getPath(), target); //????/*时 代 J a v a 公 众 号 提供*/

                    }

             
展开阅读全文