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

 

posted @ 2013-04-23 13:55  邓维  阅读(329)  评论(0编辑  收藏  举报