实现图片过滤功能

1。图片过滤处理文件,只要.gif,.jpg,.png文件

//package com.jdon.picture;

import java.io.*;
/**
*

Title:


*

Description:


*

Copyright: Copyright (c) 2002


*

Company:


* @author unascribed
* @version 1.0
*/

public class ImageFilter implements FilenameFilter
{



public boolean isGif(String file)
{
if (file.toLowerCase().endsWith(".gif")){
return true;
}else{
return false;
}
}


public boolean isJpg(String file)
{
if (file.toLowerCase().endsWith(".jpg")){
return true;
}else{
return false;
}
}

public boolean isPng(String file)
{
if (file.toLowerCase().endsWith(".png")){
return true;
}else{
return false;
}
}


public boolean accept(File dir,String fname){
return (isGif(fname) || isJpg(fname) || isPng(fname));

}

}

2。程序测试类
import java.io.File;

public class ImageFilterTest{
public static void main(String[] args){
File directory=new File("E://program//FilenameFilter//images");
String[] images = directory.list(new ImageFilter());
System.out.println("size="+images.length);
for (int i = 0; i < images.length; i++){
String imgfile=images[i];
System.out.println("imgfile="+imgfile);
}
}
}

你可能感兴趣的:(实现图片过滤功能)