29) Write a Java program to accept list of files as command line arguments. Display the name and size of all the files Delete all files with extension as ‘.html’ from the current directory. Appropriate error messages should be printed.(Use vector Array)


import java.io.*;
import java.util.*;
class DeleteFile1
{ public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter How many Files”);
int nofiles=Integer.parseInt(br.readLine());
Vector<Object> v =new Vector<Object>(nofiles);
for(int i=0;i<nofiles;i++)
{

System.out.println(“Enter File name :->”);
File file=new File(br.readLine());
v.addElement( file);
}
System.out.println(“Elements in vector:”);

File listarray[]=new File[nofiles];
v.copyInto(listarray);
System.out.println(“List of Files ->”+nofiles);
String files[]=new String[10];
for(int i=0;i<nofiles;i++)
{
if((listarray[i]).isFile()==true)
{
System.out.println(listarray[i]);
System.out.println(“Size of “+listarray[i]+” File is:-
>”+listarray[i].length());
}
else
{
System.out.println(listarray[i]);
System.out.println(listarray[i]+” File not Present”);
}
files[i]=listarray[i].toString();

}
for(int i=0;i<nofiles;i++)
{
if(files[i].endsWith(“.html”)==true)
{
System.out.println(files[i]+” is Deleted because it has Extension .Html”);
File temp=new File(files[i]);
temp.delete();
}
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s