Friday, June 8, 2012

Write a program to list files in the current working directory depending upon a given pattern.?


♣♣♣ WRITE A PROGRAM TO LIST FILES IN THE CURRENT WORKING DIRECTORY DEPENDING UPON A GIVEN PATTERN. ♣♣♣


  import java.lang.*;
  import java.io.*;

  class pro15
{
  public static void main(String ar[]) throws IOException
        {
                                    InputStreamReader a=new InputStreamReader(System.in);
                                    BufferedReader b=new BufferedReader(a);
                                    System.out.print("\n\tEnter the Directory Name : ");
            String s=b.readLine();
            File f=new File(s);
            if(f.exists())
            {
                        if(f.isDirectory())
                        {
                        String []f1=f.list();
                        int i;
                                    for(i=0;i
                                    {
                                    String tp=f1[i];
                                    if(tp.endsWith("java"))
                                    System.out.println("\n\t\t"+tp);
                                    if(tp.endsWith("class"))
                                    System.out.println("\n\t\t"+tp);
                                    }
                        }
             }
        }
}


OUTPUT :-
                                   
                        Enter The Directory Name : d:\

                                    Test.java
                                    Test.class
                                    Abc.java
                                    Abc.class
                                    Applet2.java

1 comment: