Re: How to get the line number in the code?

From: Bryce (Work) (spamtrap_at_berzerker-soft.com)
Date: 10/03/03


Date: Fri, 03 Oct 2003 10:08:25 -0400

On 2 Oct 2003 20:32:13 -0700, HGA03630@nifty.ne.jp (hiwa) wrote:

>> >Is there a way to obtain the line number in my code? For example:
>> >1 public class MyClass {
>> >2 int a = 5;
>> >3 System.out.println("Integer variable a was set on line number: " + x);
>> >4 etc.
>> >Where x is equal to '2'.
>> >
>> >How can I obtain 'x' ?
>
>You can use java.io.LineNumberReader of LineNumberInputStream. Both
>class has getLineNumber() method.

Actually, the original poster wanted to do this at runtime. I suppose
you could do some fiddling by reading the .java file into
LineNumberReader, and locating the code you were executing.