java.io package gives the facility of playing with files and directory.

Example below lists files from a directory. User inputs directory path and the file extension.

 import java.io.*;

class  testFiles 
{
    public static void main(String[] args) 
    {
         if (args.length != 2) 
        {
            System.out.println("Usage: java testFiles [directory path] " +
            "\"[file extension]\"");
            return;
        }
        try
        {
            String directory = args[0];
            String ext = args[1];
            testFiles list = new testFiles( );
            list.getFiles(directory,ext);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public void getFiles(String directory, String ext)
    {
        try
        {
            File f = new File(directory);
            boolean flag =  f.isDirectory();
            if(flag)
            {
                File fs[] = f.listFiles();
                for(int i=0;i<fs.length;i++)
                {
                    if(!fs[i].isDirectory())
                    {
                        String filename = fs[i].getName();
                        if(filename.endsWith(ext.trim()))
                                System.out.println(filename);

                    }
                }   
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}