package FileHandling;
import java.io.File;
public class FilesInDirectory {
/**
* @param args
*/
public static void main(String[] args) {
File f=new File("D:/abhi");
if(f.isDirectory())
{
System.out.println("abhi is a directory");
System.out.println("The length of directory is : "+f.length());
String[] str=f.list();
for(int i=0;i<str.length;i++)
{
File f1=new File(f.getName()+"\\"+str[i]);
if(f1.isDirectory())
{
System.out.println(str[i]+" is a directory.");
}
else
{
System.out.println(str[i]+" is a file.");
System.out.println("The length of file is : "+str[i].length());
}
}
}
else
{
System.out.println(f.getName()+" is not a Directory.");
}
}
}
Case 2 When directory was there
import java.io.File;
public class FilesInDirectory {
/**
* @param args
*/
public static void main(String[] args) {
File f=new File("D:/abhi");
if(f.isDirectory())
{
System.out.println("abhi is a directory");
System.out.println("The length of directory is : "+f.length());
String[] str=f.list();
for(int i=0;i<str.length;i++)
{
File f1=new File(f.getName()+"\\"+str[i]);
if(f1.isDirectory())
{
System.out.println(str[i]+" is a directory.");
}
else
{
System.out.println(str[i]+" is a file.");
System.out.println("The length of file is : "+str[i].length());
}
}
}
else
{
System.out.println(f.getName()+" is not a Directory.");
}
}
}
Case 1 when Directory was not there
Case 2 When directory was there
0 comments:
Post a Comment