java 之递归便利文件夹中的文件

import java.io.File;

public class Digui {
	public static void main(String[] args) {
		String fileName = "d:" + File.separator + "Finance";
		File f = new File(fileName);
		print(f);
	}

	public static void print(File f) {
		if (f != null) {
			if (f.isDirectory()) {
				File[] fileArray = f.listFiles();
				if (fileArray != null) {
					for (int i = 0; i < fileArray.length; i++) {
						print(fileArray[i]);
					}
				}
			} else {
				System.out.println(f);
			}
		}
	}
}

你可能感兴趣的:(java)