获得当前的方法名,类名,路径等当前信息

有时候要用到类对象资深的一些信息,比如方法名称,比如类名,类的路径等,,简单整理下。 获得当前JAVA类的方法名称、类名、时间等源代码

package com.tools;import java.text.SimpleDateFormat;import java.util.Date;/** * 显示JAVA类的方法名称、类名、时间等 * * @author 范芳铭 */{(String[] args){MySelf self = new MySelf();//获得当前的方法的名称String name = Thread.currentThread().getStackTrace()[1].getMethodName();System.out.println(“当前运行的方法名称:” + name);//获得当前的类的名称System.out.println(“当前的类名:” + self.getClass().getName());//类的绝对路径System.out.println(“类的绝对路径:” + Class.class.getClass().getResource(“/”).getPath());//工程的路径System.out.println(“工程的路径:” + System.getProperty(“user.dir”));//系统的当前时间SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);//设置日期格式System.out.println(“系统的当前时间:” + df.format(new Date()));// new Date()为获取当前系统时间}}

只要有信心,人永远不会挫败

获得当前的方法名,类名,路径等当前信息

相关文章:

你感兴趣的文章:

标签云: