Finding source files programatically

Suppose I have a class com.foo.Test. In that class, I want to add a method, File[] getSourceFiles() which will find the directory in which Test.class resides and return the names of all the other class files in that directory.

The problem I'm having, is that I can't get a reference to the directory containing Test.class. I can get the path information "com/foo", but I can't get the location of the "com" directory.

Is there a way to do this?

Thanks.

[487 byte] By [sgoldstein1] at [2007-9-26 1:21:05]
# 1

You can find the classpath and the location of the extensions directory from certain system properties (not sure which ones, just dump them all and you'll recognize them). Given them, you have a list of directories and jar files which you can then examine sequentially. Don't forget that your class could be in a jar file, it doesn't have to be in a directory.

DrClap at 2007-6-29 0:56:16 > top of Java-index,Core,Core APIs...
# 2
there was an article at www.javaworld.comabout this kind of problemspieler
spieler at 2007-6-29 0:56:16 > top of Java-index,Core,Core APIs...
# 3
> there was an article at www.javaworld.com> about this kind of problem> > spielerDo you recall the title of the article or approximately when it came out?Scott
sgoldstein1 at 2007-6-29 0:56:16 > top of Java-index,Core,Core APIs...
# 4
I found the article again: http://www.javaworld.com/javaworld/javatips/jw-javatip113.htmlIt's not exactly your problem, but I think it should helpanywaySpieler
spieler at 2007-6-29 0:56:16 > top of Java-index,Core,Core APIs...
# 5
Thanks!That's exactly what I was looking for. I knew this information had to be somewhere in the ClassLoader instance, but I couldn't find where. Now I know to get it through the getResource() method.Thanks, again.Scott
sgoldstein1 at 2007-6-29 0:56:16 > top of Java-index,Core,Core APIs...