如何获取当前的行号

2025-06-23 07:28:52
推荐回答(1个)
回答1:

public class Test10
{
public static void main(String args[])
{
System.out.println("This is " + getLineInfo());
}

public static String getLineInfo()
{
StackTraceElement ste = new Throwable().getStackTrace()[1];
return ste.getFileName() + ": Line " + ste.getLineNumber();
}
}