首页 > 其他 > 详细

WalkDirThreads

时间:2017-02-20 19:46:43      阅读:195      评论:0      收藏:0      [点我收藏+]

package searchdir;

 

import java.io.File;

import java.util.concurrent.ExecutorService;

import java.util.concurrent.Executors;

import java.util.concurrent.Future;

 

public class WalkDirThread {

 

static ExecutorService pool = Executors.newFixedThreadPool(10);

 

public static void main(String[] args) {

 

WalkDirThread wd = new WalkDirThread();

File file = new File("/System");

ThreadTask task = wd.new ThreadTask(file);

Future f = pool.submit(task);

 

}

 

class ThreadTask implements Runnable {

 

private File file;

 

ThreadTask(File file) {

this.file = file;

}

 

public void run() {

 

if (file.isFile()) {

 

if (file.getName().contains("sys")) {

 

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

}

 

return;

 

}

 

if (file.isDirectory()) {

 

File[] files = file.listFiles();

 

if (files == null) {

return;

}

 

for (File o : files) {

pool.submit(new ThreadTask(o));

}

 

}

 

}

 

}

 

}

 

WalkDirThreads

原文:http://www.cnblogs.com/mabel/p/6420989.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!