内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

代碼行號(hào)如何利用Java獲取

這篇文章將為大家詳細(xì)講解有關(guān)代碼行號(hào)如何利用Java獲取,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的福海網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

具體實(shí)現(xiàn)代碼:

/**
*
*/
package leo.demo.training;
/**
* Get current java file name and current code line number
* @author Leo Xie
*/
public class CurrentLine {
  /**
  * @param args
  */
  public static void main(String[] args) {
    StackTraceElement ste1 = null;
    // get current thread and its related stack trace
    StackTraceElement[] steArray = Thread.currentThread().getStackTrace();
    int steArrayLength = steArray.length;
    String s = null;
    // output all related info of the existing stack traces
    if(steArrayLength==0) {
      System.err.println("No Stack Trace.");
    } else {
      for (int i=0; i<steArrayLength; i++) {
        System.out.println("Stack Trace-" + i);
        ste1 = steArray[i];
        s = ste1.getFileName() + ": Line " + ste1.getLineNumber();
        System.out.println(s);
      }
    }
    // the following code segment will output the line number of the "new " clause
    // that's to say the line number of "StackTraceElement ste2 = new Throwable().getStackTrace()[0];"
    StackTraceElement ste2 = new Throwable().getStackTrace()[0];
    System.out.println(ste2.getFileName() + ": Line " + ste2.getLineNumber());
    // the following clause will output the line number in the external method "getLineInfo()"
    System.out.println(getLineInfo());
    // the following clause will output its current line number
    System.out.println(getLineInfo(new Throwable().getStackTrace()[0]));
  }
  /**
  * return current java file name and code line number
  * @return String
  */
  public static String getLineInfo() {
    StackTraceElement ste3 = new Throwable().getStackTrace()[0];
    return (ste3.getFileName() + ": Line " + ste3.getLineNumber());
  }
  /**
  * return current java file name and code line name
  * @return String
  */
  public static String getLineInfo(StackTraceElement ste4) {
    return (ste4.getFileName() + ": Line " + (ste4.getLineNumber()));
  }
}

關(guān)于代碼行號(hào)如何利用Java獲取就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

當(dāng)前題目:代碼行號(hào)如何利用Java獲取
當(dāng)前網(wǎng)址:http://www.rwnh.cn/article24/pgeoje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、品牌網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)搜索引擎優(yōu)化、微信小程序、虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
太原市| 高雄市| 栾城县| 汶上县| 民勤县| 育儿| 寻乌县| 自贡市| 兰西县| 鹰潭市| 甘孜县| 宁国市| 社会| 上蔡县| 都昌县| 仲巴县| 冀州市| 景德镇市| 高邑县| 从化市| 元氏县| 绥德县| 侯马市| 罗源县| 高台县| 新乐市| 广平县| 丹阳市| 乌兰察布市| 防城港市| 泰顺县| 沽源县| 东光县| 苏尼特左旗| 华亭县| 景谷| 葵青区| 乌兰察布市| 峨眉山市| 墨竹工卡县| 许昌县|