I have a Java File @ C:\Drive\MyFile.java
Now I want to read all the methods inside the java file. I know about Class.forName() but how to pass 开发者_如何学Pythonlocal path inside the forName.
you would need to compile or at least parse the java file and look for methods. you will have better luck loading the compiled class file and using http://download.oracle.com/javase/6/docs/technotes/guides/reflection/index.html
There is nothing in java that can help with .java files, just .class file. Even then, you are not assured of successfully loading an arbitrary class file, since you will probably be missing a dependency.
If I had to do this, I would run javadoc with the -public, -package, -protected and -private on every .java file I found. This gives me an HTML file with a regular format that can easily be parsed. If I was more ambitious, I would write a custom javadoc doclet. If I was crazy ambitious, I would use antlr, yacc, javacc or another parser generator with a Java grammar to parse the Java files directly.
Try using reflection, which allows you to find variables, methods, constructors, etc. defined in a Java class.
精彩评论