getting package names from classes
<p>I have this following java program which returns certain classes from a directory. I want to find the package names for these classes..how can i do that??
any code will be helpfull.</p>

<pre><code>import java.util.*;
import java.io.*;

public class CreateTestPackage
{
    public void execute()
    {
        List&lt;Class&gt; findClasses(File directory) throws ClassNotFoundException
        {

            List&lt;Class&gt; classes = new ArrayList&lt;Class&gt;();
            if (!directory.exists())
            {
                return classes;
            }
            File[] files = directory.listFiles(new FilenameFilter()
            {
                public boolean accept( File dir, String name )
                {
                    return name.matches("test.*\\.class");
                }
            });
            for (File file : files)
            {
                if (file.isDirectory())
                {
                    assert !file.getName().contains(".");
                    classes.addAll(findClasses(file));
                }
                else if (file.getName().endsWith(".class"))
                {
                    classes.add(Class.forName(file.getName().substring(0, file.getName().length() - 6)));
                }
            }
            return classes;
        }
    }




}
</code></pre>
