private void travelDir(String filepath) { String threadName = Thread.currentThread().toString(); logger.info("TargetDir:" + threadName + "==>" + filepath); File dir = new File(filepath); logger.info("dir.exists():" + threadName + "==>" + dir.exists()); if (dir.exists()) { logger.info("dir.isDirectory():" + threadName + "==>" + dir.isDirectory()); File[] files = dir.listFiles(); for (File file : files) { logger.info("file.getAbsolutePath():" + threadName + "==>" + file.getAbsolutePath()); } } }
public class CalcutateTest { @Test public void testAdd() { Calcutate cal = new Calcutate(); Class<Calcutate> c = Calcutate.class;// 获得class类 try { Method method = c.getDeclaredMethod("add", new Class[] { int.class, int.class });// 获得method.注意,这里不能使用getMethod方法,因为这个方法只能获取public修饰的方法.. method.setAccessible(true);// 这个设置为true.可以无视java的封装..不设置这个也无法获取这个Method Object result = method.invoke(cal, new Object[] { 2, 10 }); Assert.assertEquals("Must equals.",12, result);// 这里自动拆箱.. } catch (Exception e) { e.printStackTrace(); } } }