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\t%s\n", i, s.getClass());//类类型
System.out.format("ClassName:%d\t%s\n", i, s.getClassName());//类名
System.out.format("MethodName:%d\t%s\n", i, s.getMethodName());//方法名
System.out.format("FileName:%d\t%s\n", i, s.getFileName());//文件名
System.out.format("LineNumber:%d\t%s\n", i, s.getLineNumber());//行数
System.out.println("-------------------------------------------");//行数
}
}
}