public class A {
public static void main(String[] args) {
n();
}
public static void n()
{
getCaller();
}
public static void getCaller()
{
StackTraceElement stack[] = (new Throwable()).getStackTrace();
for (int i = 0; i < stack.length; i++)
{
StackTraceElement s = stack[i];
System.out.format("Class:%d %s
", i, s.getClass());//类类型
System.out.format("ClassName:%d %s
", i, s.getClassName());//类名
System.out.format("MethodName:%d %s
", i, s.getMethodName());//方法名
System.out.format("FileName:%d %s
", i, s.getFileName());//文件名
System.out.format("LineNumber:%d %s
", i, s.getLineNumber());//行数
System.out.println("-------------------------------------------");//行数
}
}
}