转自:http://singhua.javaeye.com/blog/477221 public static void getCaller() { StackTraceElement[] stack = (new Throwable()).getStackTrace(); for (int i = 0; i < stack.length; i++) { StackTraceElement ste = stack[i]; System.out.println(ste.getClassName() + "." + ste.getMethodName() + "(...);"); System.out.println(i + "--" + ste.getMethodName()); System.out.println(i + "--" + ste.getFileName()); System.out.println(i + "--" + ste.getLineNumber()); } }