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

 

相关文章:

  • 2021-08-15
  • 2021-11-17
  • 2022-12-23
  • 2022-01-28
  • 2021-12-13
  • 2021-12-26
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案