File file = new File("d:/websrc");                            
if(file.exists()){                                            
if(file.isDirectory() ){                                  
if(file.list().length<=0){                            
System.out.println("the directory is empty");     
}else{                                                
System.out.println("the directory is not empty"); 
}                                                     
}else{                                                    
System.out.println("it is not a directory");          
}                                                         
}else{                                                        
System.out.println("the file is not exist");              
}                                                             

解决方案 »

  1.   

    完整的例子:
    import java.io.*;public class isDirectory{
    public static void main(String[] args){
    File file=new File("d:/websrc");
    if(file.exists()){
    if(file.isDirectory()){
    if(file.list().length<=0){
    System.out.println("the directory is empty");
    }else{
    System.out.println("the directory is not empty");
    }
    }
    else{
    System.out.println("it is not a directory");
    }
    }
    else{
    System.out.println("the directory is not exist");
    }
    }
    }