使用FilenameFilter过滤掉chapter开头的文件。
1 public class contentFilter implements FilenameFilter { 2 public boolean isContent(String file) { 3 if (file.startsWith("chapter")){ 4 return false; 5 }else{ 6 return true; 7 } 8 } 9 public boolean accept(File dir, String name) { 10 return isContent(name); 11 } 12 }
1 public class Test { 2 public static void main(String[] args) { 3 File dir = new File("C://00006"); 4 String[] f = dir.list(new contentFilter()); 5 Arrays.sort(f); 6 System.out.println(f[f.length-1]); 7 } 8 }
图片过滤:http://jimb.iteye.com/blog/124930#bc2309281