java get line number and file name
java get line number and file name
public class LineNo { public static int getLineNumber() { return Thread.currentThread().getStackTrace()[2].getLineNumber(); } public static String getFileName() { return Thread.currentThread().getStackTrace()[2].getFileName(); } public static void main(String args[]) { System.out.println("["+getFileName()+":"+ getLineNumber()+"]"+"Hello World!"); } }
from : http://coolshell.cn/articles/611.html