import java.io.File;
import java.io.FilenameFilter;
public class FileSelect implements FilenameFilter{
static String extension = ".";
public FileSelect(String fileExtensionNoDot)
{
extension += fileExtensionNoDot;
}
public static void main(String[] args) {
File file= new File("dd/20150923184827.jpg");
System.out.println("父目录file.getParentFile()"+file.getParentFile());//父目录
System.out.println("本文件地址file.getPath()"+file.getPath());//文件目录
File file1=new File("dd");
File allFiles[]=file1.listFiles();
System.out.println("所有文件:********************");
for(File f:allFiles)
{
System.out.println(f.getName());
}
System.out.println("********************");
File[] jpgFiles= file1.listFiles(new FileSelect("jpg"));
System.out.println("jpg格式文件:********************");
for(File f:jpgFiles)
{
System.out.println(f.getName());
}
System.out.println("********************");
}
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
System.out.println("***********"+name.endsWith(".jpg"));//字符串是否以.jpg结束
return name.endsWith(".jpg");//如果是jpg就加入到jpgFiles的数组中
}
}