如何列出C盘下所有的txt文件

package com.zsh.test;

import java.io.File;
import java.io.FileFilter;

public class Test implements FileFilter {

	/**
	 * @param args
	 * @author Ben Zeph
	 */
	String condition = "";

	public Test(String condition) {
		this.condition = condition;
	}

	@Override
	public boolean accept(File pathname) {
		String filename = pathname.getName();
		if (filename.lastIndexOf(condition) != -1) {
			return true;
		} else
			return false;
	}

	public static void main(String[] args) {
		File root = new File("C://");
		File[] files = root.listFiles(new Test(".txt"));
		if (files.length != 0)
			for (int i = 0; i < files.length; i++)
				System.out.println(files[i]);
	}

}

  

原文地址:https://www.cnblogs.com/zhongshenghua/p/3582831.html