zoukankan      html  css  js  c++  java
  • [转载]在Java代码运行时获取当前和调用者的行号,方法名,类名,文件名

    public class TestClass
    {
        public static void main(String[] args)
        {
            test();
        }
    
        public static void test()
        {
            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(" 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());
            }
        }
    }

    转自:http://www.open-open.com/home/space-4097-do-blog-id-1588.html

  • 相关阅读:
    CentOS7- 配置阿里镜像源
    MySQL学习笔记
    OSI&TCP/IP模型
    加密算法学习
    golang学习笔记
    Redis学习总结整理
    TCP
    HTTP/HTTPS
    HTTP2
    MVCC
  • 原文地址:https://www.cnblogs.com/wendelhuang/p/6971194.html
Copyright © 2011-2022 走看看