DOC

java

By Pedro Walker,2014-06-23 09:38
14 views 0
java

public static void main(String[] args) throws InterruptedException {

     // 指定文件夹

     File file = new File("D:\\downloads\\");

     List<File> fileList = null;

     // 包含字符

     String filter = "j";

     if (file != null) {

     if (file.isDirectory()) {

     File[] fileArray = file.listFiles();

     if (fileArray != null && fileArray.length > 0) {

     fileList = new ArrayList<File>();

     // 包括文件;文件夹的判断

     for (File f : fileArray) {

     String fileName =

    f.getName();

     if

    (fileName.indexOf(filter) != -1) {

     fileList.add(f);

     }

     }

     }

     } else {

     System.out.println("Not Directory.");

     }

     }

     if (fileList != null && fileList.size() > 0) {

     for (File f : fileList) {

     System.out.println(f.getName());

     }

     }

     }

import java.io.*;

public class ShowFiles {

     public void showFiles(File file, int deep) {

     for(int i = 0;i<deep;i++){

     System.out.print("-");

     }

     System.out.println(file.getName());

     if(!file.isDirectory())

     return;

     File[] children = file.listFiles();

     if(children.length == 0)

     return;

     for(File child:children) {

     showFiles(child, deep + 1);

     }

     }

     public static void main(String[] args) {

     ShowFiles show = new ShowFiles();

     File file = new File("d:\\tools");

     show.showFiles(file, 0);

     }

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com