---
title: "取得JAVA下的__LINE__"
author: "luckfox"
date: "2011-05-13T13:35:05Z"
tags: []
categories: ["编程语言"]
slug: "java-line"
draft: false
lastmod: "2011-05-13T13:35:05Z"
id: 1042361
url: "https://luckfox.iteye.com/blog/1042361"
---

```

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();
    }
}

```