java HW 7.3

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java HW 7.3相关的知识,希望对你有一定的参考价值。

package com.gmail.vhrushyn;

import java.io.File;

public class Searcher implements Runnable {

	private File where;
	private String name;

	public Searcher(File where, String name) {
		super();
		this.where = where;
		this.name = name;
	}

	private void MySearch() {
		File[] files = where.listFiles();
		for (File file : files) {
			if (file.isDirectory()) {
				Thread t = new Thread(new Searcher(file, name));
				t.start();
			}
			if (file.getName().equalsIgnoreCase(name)) {
				System.out.println(file.getPath());
			}
		}
	}

	public void run() {
		MySearch();
	}

}
package com.gmail.vhrushyn;

import java.io.File;

public class Main {

	public static void main(String[] args) {

		File where = new File("F:/Java"); // folder where to search

		String name = "main.java";  // name of file to find

		Thread t = new Thread(new Searcher(where, name));
		t.start();

	}

}

以上是关于java HW 7.3的主要内容,如果未能解决你的问题,请参考以下文章

java HW05

java HW 10.4

java HW 7.2

java HW 7.1

java HW 6.2

java HW 5.3-5.4