1 Packagecom.test;2 3 Importjava.io.IOException;4 ImportJava.io.InputStream;5 Importjava.lang.reflect.InvocationTargetException;6 ImportJava.lang.reflect.Method;7 Importjava.util.Properties;8 9 Public classTest {Ten One /** A * - * @paramb parameter List - * @parama the * @return - */ - PublicString A (intBinta) { -String bb=b+2+ ""; + System.out.println (a); -System.out.println ("Through Inverse color"); + returnBB; A } at - - Public Static voidMain (string[] args)throwsSecurityException, Nosuchmethodexception, IllegalArgumentException, Illegalaccessexception, invocationtargetexception { - - //read the configuration file to get the key value for the signature -InputStream InputStream =NewTest (). GetClass (). getClassLoader (). getResourceAsStream ("Log4j.properties"); inProperties p =NewProperties (); - Try{ to p.load (inputstream); +}Catch(IOException E1) { - e1.printstacktrace (); the } *String a = P.getproperty ("234234234");//string variable of method $Test test=NewTest ();Panax NotoginsengClass SS =int.class; -Class SA =int.class; theClass b[] =NewCLASS[2];//array of parameter types + AB[0] = SS;//the type of the first parameter theB[1]= sa;//the type of the second parameter +Method get =Test.getclass (). GetMethod (A, b); - $ //the class that invokes the method, the argument list $String AA = (string) get.invoke (test,NewInteger (3),NewInteger (3)); - System.out.println (AA); - } the - Wuyi log4j.properties the - Wu234234234=a - About $ - - - A /** + * Read the properties file under the path to get the properties object the * @paramPath - * @returnProperties $ * @throwsIOException the */ the Public StaticProperties getProperties (String fileName)throwsioexception{ theString FilePath = Contentsmethod.class. GetResource ("/"). GetPath () +FileName; theFileInputStream in =NewFileInputStream (NewFile (FilePath)); -Properties p =NewProperties (); in p.load (in); theLogger.info ("contentsmethod.getproperties = load Config file" +FilePath); the returnp; About}
Java Reflection Instance