Here we are Showing a methodString [] names=mydir.list();That is helpfull to get all directorywith this we can doing a looping on this .
import java.io.*;
import java.util.*;
class FileTotalDirectory
{
public static void main(String args[])
{
//get number of files in a directory and its subdirectories
File mydir=new File("D:/Assignments");
String [] names=mydir.list();
System.out.println("Total memebers in directory "+mydir.getName()+" are "+names.length);
for(String s:names)
{
System.out.println(s);
}
}
}
Here we are Showing a detail of directory using java methodThat is helpfull to get all info of directorywith this we can doing a looping on this .
import java.io.*;
import java.util.*;
class FileTotalDirectory
{
public static void main(String args[])
{
File mydir=new File("D:/Assignments");
File [] names=mydir.listFiles();
System.out.println("Total memebers in directory "+mydir.getName()+" are "+names.length);
for(File s:names)
{
long ms=s.lastModified();
Date dt=new Date(ms);
if(s.isFile())
System.out.println(s.getName()+" is a file and was last mod on "+dt);
else
System.out.println(s.getName()+" is a directory and was last mod on "+dt);
}
}
}