Java Blog

 
 
 
import java.io.File;

class  DirList
{
    public static void main(String[] args) 
    {
         String dirname= \"e:/songs\";
         File f1 = new File(dirname);

    if (f1.isDirectory())
    {
              System.out.println(\"Directory of \" + dirname);
              String s[] = f1.list();

              for (int i=0;i<s.length ;i++ )
              {
                    File f = new File(dirname + \"/\"+ s[i]);
                    if (f.isFile()){
                         System.out.println(s[i] + \" is a File\");
                    }
                    else{
                        System.out.println(s[i] + \" is a directory\");
                    }
              }
     }
    else
    {
           System.out.println(dirname + \" is not  a directory\");
    }
    }
}

 
 
Didn't find what you were looking for? Find more on File handling program to display directory contents