閱讀193 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Command設計模式-文件過濾器FilenameFilter

import java.io.*;

/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@163.com
 * @version  1.0
 */
public class FilenameFilterTest
{
	public static void main(String[] args) 
	{
		File file = new File(".");
		String[] nameList = file.list(new MyFilenameFilter());
		for (String name : nameList)
		{
			System.out.println(name);
		}
	}
}
//實現自己的FilenameFilter實現類
class MyFilenameFilter implements FilenameFilter
{
	public boolean accept(File dir, String name)
	{
		//如果文件名以.java結尾,或者文件對應一個路徑,返回true
		return name.endsWith(".java")
			|| new File(name).isDirectory();
	}
}


最後更新:2017-04-03 20:43:08

  上一篇:go Never store the password unhased directly on the server!
  下一篇:go iOS網絡編程-iOS中解析Bonjour服務