?? In the C language, you can get the file name and line number through the macro file, lines, in the Java language, you can get the file name, class name, Stacktraceelement class Method name, line number, specific code is as follows:
public static int Getlinenumber () { stacktraceelement[] stackTrace = new Throwable (). Getstacktrace (); return Stacktrace[1].getlinenumber ();} public static String Getmethodname () { stacktraceelement[] stackTrace = new Throwable (). Getstacktrace (); return Stacktrace[1].getmethodname ();} public static String GetFileName () { stacktraceelement[] stackTrace = new Throwable (). Getstacktrace (); return Stacktrace[1].getfilename ();} public static String GetClassName () { stacktraceelement[] stackTrace = new Throwable (). Getstacktrace (); return Stacktrace[1].getclassname ();}
Ways to get the file name, class name, method name, line number in Java