标签:lib over cep filename 文件 base print for 知识
Java.io.FilenameFilter是文件名过滤器,用来过滤不符合规格的文件名,并返回合格的文件;
package cn.test; import java.io.File; import java.io.FilenameFilter; import org.junit.Test; public class Demo4 { @Test public void test1(){ File file = new File("D:/Temp"); FilterBysuffix filter = new FilterBysuffix(".txt"); String[] files = file.list(filter); for (String fileName : files){ System.out.println(fileName); } } } class FilterBysuffix implements FilenameFilter{ private String suffix; public FilterBysuffix(String suffix){ this.suffix=suffix; } @Override public boolean accept(File dir, String name) { return name.endsWith(suffix); } }
结果:
标签:lib over cep filename 文件 base print for 知识
原文地址:http://www.cnblogs.com/zydev/p/7191182.html